Is there a way to make a modern shell's history feature be scoped to a path?
My working contexts are split up as paths on the file system, and the pattern of shell activity, such as repeatedly issued commands, tends to be distinct to each 'project'. It would be nice if I could scope the history feature to commands issued from the current path (or sub-path).
Best Answer
With
zsh
, you could do:And add to your ~/.zshrc:
chpwd()
is called whenever the current directory changes. There, we reset the history file to something like~/.zsh/dirhist/@foo@bar
when youcd
to/foo/bar
.