Last active
November 26, 2015 02:31
-
-
Save benjaminblack/6ec8ec9d97be8e9cc4da to your computer and use it in GitHub Desktop.
Bash functions implementing working directory history
This file contains hidden or 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/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