Skip to content

Instantly share code, notes, and snippets.

@riccardosven
Last active August 29, 2015 14:02
Show Gist options
  • Save riccardosven/b14eaf568a240f9d0486 to your computer and use it in GitHub Desktop.
Save riccardosven/b14eaf568a240f9d0486 to your computer and use it in GitHub Desktop.
Oh-my-zsh plugin that saves the dirstack between sessions and keeps the pwd consistent.
DIRSTACKSIZE=9
DIRSTACKFILE=~/.zdirs
if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then
dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
[[ -d $dirstack[1] ]] && cd $dirstack[1]
fi
function chpwd() {
print -l $PWD ${(u)dirstack}> $DIRSTACKFILE
}
jump() {
blue=$(tput setaf 4)
green=$(tput setaf 2)
normal=$(tput sgr0)
i=1
for dir in $dirstack
do
printf "%40s\n" "[${blue}$i${normal}] ${green}$dir${normal}"
let i+=1
done
printf "jump to directory: "
read dir
cd $dirstack[$dir]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment