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