2 ms·
I got burned a couple of times in the past with bash-history, and go a small step beyond this, even on zsh, and added to .zshrc: preexec_custom_history() {
by misnome 4y ago
I got burned a couple of times in the past with bash-history, and go a small step beyond this, even on zsh, and added to .zshrc:
preexec_custom_history() {
echo "$HOSTNAME $$ $(date "+%Y-%m-%dT%H:%M:%S%z") $1" >> "~/.fullhistory"
}
preexec_functions+=(preexec_custom_history)
I work on a lot of shared-filesystem computers, and so it's useful to be able to filter for commands ~year ago when I know what computer I was on when I ran it. I have a fzf binding to search through this with ctrl-r, and it's otherwise easily greppable.
When I was still using bash, I had this same thing using https://github.com/rcaloras/bash-preexec https://github.com/rcaloras/bash-preexec .
- cassianoleal 4y agoThanks, this looks great! How does the history know that the prefix (hostname, PID, date) is not part of the command though? I mean, I tested it and it works as expected (without them) but I'm really curious about how it works.
- misnome 4y agoFor searching/expansion, it's a constant number of fields I use my own ctrl-r handler, which just runs `cut -d" " -f 4-`. Before that, I just used the standard history and used this as a comprehensive backup - grep, and seeing everything in context was valuable for me alone.