Created
January 21, 2017 13:55
-
-
Save axel-angel/293e7d9ad1cbb9c08af7ee43bb08a1b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# relative history | |
relative_histfile() { | |
searchdir="$(readlink -f $PWD)"; | |
# default values | |
if [ -z "$HISTDIR" ]; then | |
HISTDIR="$HOME/.histfiles/"; | |
fi | |
if [ -z "$HISTFILE_DEFAULT" ]; then | |
HISTFILE_DEFAULT="$HOME/.histfile" | |
fi; | |
# find first histfile starting from pwd up to / | |
while true; do | |
histtarget="${HISTDIR}/${searchdir//\//%}" | |
if [ -e "$histtarget" ] || [ "$searchdir" = "/" ]; then | |
break; | |
fi; | |
searchdir="$(readlink -f "$searchdir/..")"; | |
done; | |
# load relative history or default one | |
if [ "$searchdir" = "/" ]; then | |
if [ "$HISTFILE" != "$HISTFILE_DEFAULT" ]; then | |
echo "> load default history"; | |
fc -Pp "$HISTFILE_DEFAULT"; | |
fi; | |
else | |
echo "> load history for $searchdir"; | |
fc -Pp "$histtarget"; | |
fi; | |
} | |
chpwd_functions+=(relative_histfile); | |
relative_histfile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment