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 .
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.
There can be other reasons for wanting a smallish history besides fast startup like wanting low history numbers if you learnt all the ancient `!` history escapes that were the main way of using history with csh going back forty-plus years ago. This is also one of the reasons why extension theme frameworks like oh-my-zsh have become popular - much of what they do is enable bells and whistles that are features of the core shell.
HISTFILE The file to save the history in when an interactive shell exits. If unset, the history is not saved.
0. https://web.archive.org/web/20221012011928id_/zsh.sourceforg...