Closed biocyberman closed 5 years ago
You could hack in this functionality for cd
, but I do not think this is possible at a larger scale.
If my memory serves me correctly, this plugin mirror directory structure under ~/.per_directory_history
or something like that. So in the example, I will have ~/.per_directory_history/$HOME/testdir/testsubdir`. Can we make use of this fact and print the directory for the command?
If that is not the case, somehow I have to record ZSH History with $PWD in addition to the command itself to make this work. Should there be a hack on how HISTORY
format at ZSH side?
Thanks to this answer on stack overflow, I modified this function:
function _per-directory-history-addhistory() {
# respect hist_ignore_space
if [[ -o hist_ignore_space ]] && [[ "$1" == \ * ]]; then
true
else
print -Sr -- "${1%%$'\n'}"
fc -p $_per_directory_history_directory
fi
}
To this version:
function _per-directory-history-addhistory() {
# respect hist_ignore_space
if [[ -o hist_ignore_space ]] && [[ "$1" == \ * ]]; then
true
else
print -Sr -- "${1%%$'\n'} ### ${PWD}"
fc -p $_per_directory_history_directory
fi
}
And it works perfectly the way I want :)
I ran commands and jumped everywhere. Now I use
ctrl - g
andctrl - r
to search back history. When I find a command, I want to jump to the correct directory to run that command. For example:At this point, I enable search global and search for "testsubdir" If I run
mkdir -p testsubdir
again under $HOME, it will create testsubdir under $HOME. This is not what I want. I want to know that I ran the command undertestdir
to work correctly. How do I find that out?