I would like to keep a directory of shell history files, one for each shell session. For instance, if there are two shell sessions, there are two history files. I would like the ability to search these files and purge histories of past sessions. Does anyone have a solution?
So far my solution:
.kshrc
export HISTFILE="$HOME/.hist/history.$$"
# delete history PID files that are not active
function purge_hist {
for i in $(comm -23 <(sort -n <(ls $HOME/.hist/history.* | sed "s#$HOME/.hist/history.##")) <(sort <(for i in $(ps -ex -o pid | sed 1d); do echo $i ; done))); do echo "$HOME/.hist/history.$i"; done | xargs rm -f
}
# ksh history files are binary
function view_hist {
strings -n 1 $0
}
This solution is not optimal. There could be two invocations of the shell where the PID is the same. Therefore there must be an additional identified prepended to the history files indicating the session of the OS.
Any suggestions appreciated.
Thanks