Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]: Comments in bash are not logged #2537

Closed
1 task done
TopherIsSwell opened this issue Jan 9, 2025 · 3 comments
Closed
1 task done

[Bug]: Comments in bash are not logged #2537

TopherIsSwell opened this issue Jan 9, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@TopherIsSwell
Copy link

TopherIsSwell commented Jan 9, 2025

What did you expect to happen?

I expected this to function like bash history and record comments in the history.

Sometimes I begin writing a complex command and then realize I need more information before I can finish it, so I add a pound at the beginning of the command and press enter so its in my bash history. I collect the needed information, then I Ctrl-R to bring up the commented command and I remove the comment and finish the command.

Contrived example:

$ #for host in prod1e{1,2,3}-nginx-{1,2}; do rsync -avu "$host":/dev/ ...
$ ls /dev
$ for host in prod1e{1,2,3}-nginx-{1,2}; do rsync -avu "$host":/dev/cpuinfo "./$host-cpuinfo"; done

What happened?

Commands beginning with # are excluded from the history. However commands with a comment at the end of the line are included which is expected. They don't show up in Ctrl-R search. They do show up in bash's session history (I've disabled the keybinding in atuin, and when I press to navigate history, it's using bash and I see the commented commands).

$ echo comment #comment
comment

$ echo comment follows
comment follows

$ #My little comment

$ echo comment before this
comment before this

$ sqlite3 ~/.local/share/atuin/history.db 'select command from history order by timestamp desc limit 5;'
sqlite3 ~/.local/share/atuin/history.db 'select command from history order by timestamp desc limit 5;'
echo comment before this
echo comment follows
echo comment #comment
PS1="\$"

Requested fix

As a non-breaking fix, if there was a log_comments option in the config, then people who desire to have comments in their history would have the option without changing the default behavior for anyone who's come to expect/rely on comments being omitted.

Atuin doctor output

$ atuin doctor
Atuin Doctor
Checking for diagnostics


Please include the output below with any bug reports or issues
{
  "atuin": {
    "version": "18.4.0",
    "sync": null,
    "sqlite_version": "3.46.0"
  },
  "shell": {
    "name": "bash",
    "default": "bash",
    "plugins": [
      "atuin",
      "bash-preexec"
    ],
    "preexec": "bash-preexec"
  },
  "system": {
    "os": "Fedora Linux",
    "arch": "x86_64",
    "version": "41",
    "disks": [
      {
        "name": "/dev/mapper/luks-9556d59c-31c9-42dd-b764-b55c36b97b0e",
        "filesystem": "xfs"
      },
      {
        "name": "/dev/vda3",
        "filesystem": "xfs"
      },
      {
        "name": "/dev/mapper/luks-fee58fff-f51d-4b58-8105-9e5167fbd205",
        "filesystem": "xfs"
      }
    ]
  }
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TopherIsSwell TopherIsSwell added the bug Something isn't working label Jan 9, 2025
@akinomyoga
Copy link
Contributor

As described in README, bash-preexec has a limitation. The behavior reported in this PR is actually the limitation. For details, ee [Bash]-[bash-preexec] on Installing the shell plugin - Atuin Docs. Check also the upstream issue rcaloras/bash-preexec#158.

@TopherIsSwell
Copy link
Author

Thanks for letting me know, I must have missed that note. I can confirm in my testing that using ble.sh does add comments to the history.

Ironically in the link you provided it says there's a limitation around bash-preexec not respecting ignorespace in $HISTCONTROL, and while I trust that is true, when that's enabled I'm not getting the command logged in my $HISTFILE or in my session history in bash or in Atuin history, which is nice.

If this is purely an issue with the upstream code, I'll close this one.

Note: testing with Bash 5.3 beta and bash-preexec master doesn't eliminate this bug for me.

@akinomyoga
Copy link
Contributor

Note: testing with Bash 5.3 beta and bash-preexec master doesn't eliminate this bug for me.

I didn't write the mater works. I wrote rcaloras/bash-preexec#28 (comment) works, which is not included in the master branch. As an actual implementation, you can test the head branch of rcaloras/bash-preexec#166, i.e., the PS0-funsub branch of akinomyoga/bash-preexec.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants