From eeaef9ee493bf409118d0ca8d75bf6b0ba4cee36 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Tue, 13 Nov 2012 10:51:39 +0200 Subject: [PATCH] --- qcd_function | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 qcd_function diff --git a/qcd_function b/qcd_function new file mode 100644 index 0000000..0263e8f --- /dev/null +++ b/qcd_function @@ -0,0 +1,61 @@ +function cd_history () { + if [ -z "$1" ] + then \cd "$HOME" + return + fi + old=$( tail -n 49 "$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 +}