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" case="-i"
;; ;;
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 touch ~/.qcd ~/.bash_cdhistory
return return
;; ;;
L) L)
echo ==History ~/.bash_cdhistory: echo '## History ~/.bash_cdhistory ##'
cat ~/.bash_cdhistory cat ~/.bash_cdhistory
echo echo
echo ==Saved ~/.qcd: echo '## Saved ~/.qcd ##'
cat ~/.qcd cat ~/.qcd
return return
;; ;;
@@ -146,7 +128,7 @@ complete -F _qcd qcd
;; ;;
h) h)
echo 'qcd [-hiLm]|[-al] [name] echo 'qcd [-hiLm]|[-al] [name]
Version: 2017-03-24 Version: 2018-11-16
Change current working path based on the list ~/.qcd Change current working path based on the list ~/.qcd
Keeps a history of folders visited in ~/.bash_cdhistory 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 the basename will be used
-e [name] Show the match, store in variable QCD -e [name] Show the match, store in variable QCD
-i Case insensitive search, must come first. -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 [name] Show the match, but do not change
-L Lists the paths -L Lists the paths
-m Maintain the list, deleting non-existing entries' -m Maintain the list, deleting non-existing entries'
@@ -181,8 +163,20 @@ Keeps a history of folders visited in ~/.bash_cdhistory
if [ ! -z "$d" ] if [ ! -z "$d" ]
then \cd "$d" then \cd "$d"
fi 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() { function ncd() {
# echo Next sibling cd # echo Next sibling cd
@@ -340,11 +334,11 @@ function whenfilechanges() {
} }
otime[$i]=$( stat -c %Z "${fname[$i]}" ) otime[$i]=$( stat -c %Z "${fname[$i]}" )
done done
while : while :; do
do ntime=() ntime=()
for ((i=0;i<${#fname[@]};i++)) for ((i=0;i<${#fname[@]};i++)); do
do ntime[$i]=$( stat -c %Z "${fname[$i]}" ) ntime[$i]=$( stat -c %Z "${fname[$i]}" )
[ "${ntime[$i]}" -ne "${otime[$i]}" ] && { [[ "${ntime[$i]}" -ne "${otime[$i]}" ]] && {
echo "${fname[$i]} changed:" echo "${fname[$i]} changed:"
otime[$i]=$( stat -c %Z "${fname[$i]}" ) otime[$i]=$( stat -c %Z "${fname[$i]}" )
eval "$@" eval "$@"
@@ -356,7 +350,6 @@ function whenfilechanges() {
read -t 2 forced read -t 2 forced
[ $? -eq 0 ] && eval "$@" [ $? -eq 0 ] && eval "$@"
done done
} }
# Shell enhancement # Shell enhancement