Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminblack/6ec8ec9d97be8e9cc4da to your computer and use it in GitHub Desktop.
Save benjaminblack/6ec8ec9d97be8e9cc4da to your computer and use it in GitHub Desktop.
Bash functions implementing working directory history
#!/bin/bash
export WDHIST=( $(pwd) )
function cd {
builtin cd $*
if [ $? -eq 0 ]; then
WDHIST[${#WDHIST[*]}]=$(pwd)
fi
}
function cdhist {
local len=${#WDHIST[*]}
for (( i = 0; i < $len; i++ )); do
printf " %4d %s\n" $i ${WDHIST[$i]}
done
}
function cd_ {
if [ $# -ne 1 ]; then
echo "Usage: cd_ <#> (# from cdhist)"
return
fi
builtin cd ${WDHIST[$1]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment