completion for qcd
This commit is contained in:
53
qcd_function
53
qcd_function
@@ -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,11 +334,11 @@ 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]}" ] && {
|
||||
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 "$@"
|
||||
@@ -356,7 +350,6 @@ function whenfilechanges() {
|
||||
read -t 2 forced
|
||||
[ $? -eq 0 ] && eval "$@"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
# Shell enhancement
|
||||
|
||||
Reference in New Issue
Block a user