added qcd -l name to find the match

This commit is contained in:
q
2013-04-25 07:41:02 +03:00
parent af600aab44
commit 8aa566f802

View File

@@ -13,27 +13,38 @@ function cd_history () {
alias cd=cd_history alias cd=cd_history
function qcd() { function qcd() {
while getopts alhm opt local OPTIND
local OPTARG
while getopts aLl:hm opt
do case "$opt" in do case "$opt" in
a) a)
# Adding # Adding
name=${!OPTIND} local name=${!OPTIND}
if [ -z "$name" ] if [ -z "$name" ]
then name=$( basename $( pwd )) then name=$( basename $( pwd ))
fi fi
echo "$name":$( pwd ) echo "$name":$( pwd )
echo "$name":$( pwd ) >> ~/.qcd echo "$name":$( pwd ) >> ~/.qcd
return
;;
L)
echo ==History ~/.bash_cdhistory:
cat ~/.bash_cdhistory
echo
echo ==Saved ~/.qcd:
cat ~/.qcd
return
;; ;;
l) l)
echo ==History ~/.bash_cdhistory: local d=$( grep -h ^"$OPTARG" ~/.qcd <( tac ~/.bash_cdhistory ) | head -n 1 )
cat ~/.bash_cdhistory d=${d/*:/}
echo echo $d
echo ==Saved ~/.qcd: return
cat ~/.qcd
;; ;;
m) m)
IFS=$'\n' local IFS=$'\n'
for line in $( cat ~/.bash_cdhistory ); for line in $( cat ~/.bash_cdhistory );
do if [ -d "${line/*:/}" ]; do if [ -d "${line/*:/}" ];
then echo "$line" >> ~/.bash_cdhistory.tmp then echo "$line" >> ~/.bash_cdhistory.tmp
@@ -46,22 +57,21 @@ function qcd() {
fi fi
done done
mv ~/.qcd.tmp ~/.qcd mv ~/.qcd.tmp ~/.qcd
return
;; ;;
h) h)
echo "qcd [-al] [name]" echo 'qcd [-mLh]|[-al] [name]
echo "Change current working path based on the list ~/.qcd" Change current working path based on the list ~/.qcd
echo "Keeps a history of folders visited in ~/.bash_cdhistory" Keeps a history of folders visited in ~/.bash_cdhistory
echo " "
echo "qcd -a [name]" -a [name] Adds the path to the list
echo " Adds the path to the list" You may add the name of the path, but when omitted
echo " You may add the name of the path, but when omitted" the basename will be used
echo " the basename will be used"
echo " " -l [name] Show the match, but do not change
echo "qcd -l " -L Lists the paths
echo " Lists the paths" -m Maintain the list, deleting non-existing entries'
echo " " return
echo "qcd -m "
echo " Maintain the list files, deleting non-existing entries"
;; ;;
esac esac
done done