completion for qcd

This commit is contained in:
ville rantanen
2018-11-16 10:52:07 +02:00
parent c4b484a7b9
commit 7b78f12f08

View File

@@ -84,32 +84,14 @@ function qcd() {
case="-i"
;;
I)
echo "See ~/.bash_completion for possible duplicates"
echo '
have qcd &&
_qcd()
{
local cur
local d
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "-a -i -h -l -L -m" -- $cur ) )
return 0
fi
COMPREPLY=( $( compgen -W "$( grep -h ^"$cur" ~/.qcd <( tac ~/.bash_cdhistory ) | cut -d: -f1 )" ) )
}
complete -F _qcd qcd
' >> ~/.bash_completion
. /etc/bash_completion
touch ~/.qcd ~/.bash_cdhistory
return
;;
L)
echo ==History ~/.bash_cdhistory:
echo '## History ~/.bash_cdhistory ##'
cat ~/.bash_cdhistory
echo
echo ==Saved ~/.qcd:
echo '## Saved ~/.qcd ##'
cat ~/.qcd
return
;;
@@ -146,7 +128,7 @@ complete -F _qcd qcd
;;
h)
echo 'qcd [-hiLm]|[-al] [name]
Version: 2017-03-24
Version: 2018-11-16
Change current working path based on the list ~/.qcd
Keeps a history of folders visited in ~/.bash_cdhistory
@@ -155,7 +137,7 @@ Keeps a history of folders visited in ~/.bash_cdhistory
the basename will be used
-e [name] Show the match, store in variable QCD
-i Case insensitive search, must come first.
-I Install, with autocompletion (use only once)
-I Install (use only once)
-l [name] Show the match, but do not change
-L Lists the paths
-m Maintain the list, deleting non-existing entries'
@@ -181,8 +163,20 @@ Keeps a history of folders visited in ~/.bash_cdhistory
if [ ! -z "$d" ]
then \cd "$d"
fi
} # qcd ends
}
_qcd()
{
local cur
local d
cur=${COMP_WORDS[COMP_CWORD]}
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "-a -i -h -l -L -m" -- $cur ) )
return 0
fi
COMPREPLY=( $( compgen -W "$( grep -h ^"$cur" ~/.qcd <( tac ~/.bash_cdhistory ) | cut -d: -f1 )" ) )
}
complete -F _qcd qcd
# qcd ends
function ncd() {
# echo Next sibling cd
@@ -340,23 +334,22 @@ function whenfilechanges() {
}
otime[$i]=$( stat -c %Z "${fname[$i]}" )
done
while :
do ntime=()
for ((i=0;i<${#fname[@]};i++))
do ntime[$i]=$( stat -c %Z "${fname[$i]}" )
[ "${ntime[$i]}" -ne "${otime[$i]}" ] && {
echo "${fname[$i]} changed:"
otime[$i]=$( stat -c %Z "${fname[$i]}" )
eval "$@"
echo -n "Waiting for file changes... "
date
}
done
echo -ne Waiting.. $( date )\\r
read -t 2 forced
[ $? -eq 0 ] && eval "$@"
while :; do
ntime=()
for ((i=0;i<${#fname[@]};i++)); do
ntime[$i]=$( stat -c %Z "${fname[$i]}" )
[[ "${ntime[$i]}" -ne "${otime[$i]}" ]] && {
echo "${fname[$i]} changed:"
otime[$i]=$( stat -c %Z "${fname[$i]}" )
eval "$@"
echo -n "Waiting for file changes... "
date
}
done
echo -ne Waiting.. $( date )\\r
read -t 2 forced
[ $? -eq 0 ] && eval "$@"
done
}
# Shell enhancement