Instead of this, I keep a permanent log of every shell command I ever typed and have a handy alias to keep through it. It also keeps track of the directory a command was run from, so I can limit my search. That way if I ever want to get back into a project I was working on long ago, I can just grep for commands run from that directory. Not only that, but I can use it to cd to directories quickly. So if I was working…
How do I get this?
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> "${HOME}/bash_logs_$(hostname)/bash-history-$(date "+%Y-%m-%d").log"; fi'
in your ~/.bash_profile. You also may need to `mkdir "${HOME}/bash_logs_$(hostname)"`
I took this command from a Hacker News thread of the past. I don't have a link to it any more.