News for hackers. Stuff that matters.
Re:Better Shell History Search by yb303 on Thursday March 27, 2025 @07:46PM (#43499599)
I have my own solution that I've been using for many years — I record all my bash history.

Bash has a hook (cannot remember the name on my phone) that is called on every command.

It's easy enough to write into a file the command together with the directory and git branch.

Then I can grep it with a bash function that colors the dir and branch in the output.

It does not replace ctrl-r but it's a great addition especially when running multiple sessions and bash saving just the last one

Re:Better Shell History Search by rascul on Thursday March 27, 2025 @08:43PM (#43500038)
> Bash has a hook (cannot remember the name on my phone) that is called on every command.

$PROMPT_COMMAND

https://www.gnu.org/software/bash/manual/html_node/Bash-Vari...

Re:Better Shell History Search by bandie91 on Friday March 28, 2025 @04:52AM (#43503054)
> Bash has a hook (cannot remember the name on my phone) that is called on every command.

trap 'echo "$BASH_COMMAND" >> ~/.bash_history_extra' DEBUG

this runs before commands, not after the whole command line (before prompt is displayed).

my personal bash history tweak suit is based on this. with a load of complexity of course, because the DEBUG trap is also triggered before each PROMPT_COMMAND commands and on every simple command within the issued command line. so the above example would record each command of a pipeline separately.