2 ms·
I have had this snippet in my .bashrc for ages: function cwd() { cd "$1" || return if [ -w "${PWD}/.bash_history" ]; then history -a hist
by tremon 5y ago
I have had this snippet in my .bashrc for ages:
function cwd() {
cd "$1" || return
if [ -w "${PWD}/.bash_history" ]; then
history -a
history -c
HISTFILE="${PWD}/.bash_history"
history -r
fi
if [ -r "${PWD}/.bashrc" ]; then
source "${PWD}/.bashrc"
fi
}
Yes, a contextual history is very valuable, but the context isn't necessarily tied to the directory I'm currently in. Like git does as well, I'd want an entire subtree to share the same history. I'm sure that there's more elegant solutions for it than having to explicitly use cwd instead of cd to change contexts, but so far it's served me well.