7 ms·
In our research group (with shared NFS), we log the history per directory (i.e. the histfile is $PWD/.history.$USER), and we also log the date/time. This has be
by albertzeyer 7y ago
In our research group (with shared NFS), we log the history per directory (i.e. the histfile is $PWD/.history.$USER), and we also log the date/time. This has been extremely helpful. Not only checking your own history, but also being able to see others history. E.g. imagine going through some directories of some former colleague who is gone now. Otherwise it would often be impossible to really understand how sth was created, or ended up that way, etc. I mean, properly documenting everything is of course nice, but even if that is done consistently, it will still miss some details. And in practice, it never is done consistently.
I wonder why this is not more standard. Most shells write a single global histfile to $HOME.
- sdoering 7y agohow do you configure this? I would love to use this.
- albertzeyer 7y agoIt's a very custom solution. For Bash, in ~/.bashrc: export PROMPT_COMMAND="myLocalHistory" # we don't need everything within the history alias useHistory='grep -E -v "^ls$|^ll$|^l$|^dir$|^cd |^bg$|^fg$|^qstat |^note |^mutt|^std|^clear$|^qinfo$|^gh|^qw$" | wc -l' function myLocalHistory() { HISTORYLINE=`history | tail -1 | sed 's:^ *[0-9]* *::g'` if [ `echo $HISTORYLINE | useHistory` == 1 ] ; then ((date +%F.%H-%M-%S | tr -d '\n' ; echo " $HISTORYLINE") >>.history.$USER) 2>/dev/null fi } For ZSH, in ~/.zshrc: preexec () { ~/dotfiles/system-tools/helpers/local-history-add.py $1 >/dev/null } For Fish, in ~/.config/fish/config.fish: function fish_preexec --on-event fish_preexec ~/dotfiles/system-tools/helpers/local-history-add.py $argv & end The script local-history-add.py is here: https://github.com/albertz/helpers/blob/master/local-history-add.py https://github.com/albertz/helpers/blob/master/local-history... The Bash solution probably could also be simplified by using this script, which takes care of filtering logic and adding it to the history file, in your preferred format.