function cd_history () { if [ -z "$1" ] then \cd "$HOME" return fi old=$( tail -n 149 "$HOME/.bash_cdhistory" ) echo "$old" > "$HOME/.bash_cdhistory" \cd "$1" p=$( pwd ) b=$( basename "$p" ) echo $b":"$p >> "$HOME/.bash_cdhistory" } alias cd=cd_history function qcd() { while getopts alh opt do case "$opt" in a) # Adding name=${!OPTIND} if [ -z "$name" ] then name=$( basename $( pwd )) fi echo "$name":$( pwd ) echo "$name":$( pwd ) >> ~/.qcd ;; l) echo ==History ~/.bash_cdhistory: cat ~/.bash_cdhistory echo echo ==Saved ~/.qcd: cat ~/.qcd ;; h) echo "qcd [-al] [name]" echo "Change current working path based on the list ~/.qcd" echo "Keeps a history of folders visited in ~/.bash_cdhistory" echo " " echo "qcd -a [name]" echo " Adds the path to the list" echo " You may add the name of the path, but when omitted" echo " the basename will be used" echo " " echo "qcd -l " echo " Lists the paths" ;; esac done unset OPTSTRING unset OPTIND if [ -z "$1" ] then \cd else d=$( grep ^"$1" ~/.qcd ~/.bash_cdhistory | head -n 1 ) d=${d/*:/} if [ ! -z "$d" ] then \cd "$d" fi fi }