completion for qcd
This commit is contained in:
109
qcd_function
109
qcd_function
@@ -2,9 +2,9 @@
|
||||
## improved CD commands:
|
||||
_QCD_FIND=find
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
darwin*)
|
||||
alias tac=gtac
|
||||
_QCD_FIND=gfind
|
||||
_QCD_FIND=gfind
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -35,7 +35,7 @@ function hcd() {
|
||||
d=$( tail -n 20 "$HOME/.bash_cdhistory" | head -n 19 | cut -d: -f2 | tac | cat -n | sed 's,^ \+,,' | grep -h "^$1 " )
|
||||
d=${d/* /}
|
||||
if [ ! -z "$d" ]
|
||||
then \cd "$d"
|
||||
then \cd "$d"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ function qcd() {
|
||||
local opt
|
||||
local case
|
||||
local d
|
||||
[ -e ~/.qcd ] || touch ~/.qcd
|
||||
[ -e ~/.bash_cdhistory ] || touch ~/.bash_cdhistory
|
||||
[ -e ~/.qcd ] || touch ~/.qcd
|
||||
[ -e ~/.bash_cdhistory ] || touch ~/.bash_cdhistory
|
||||
while getopts ae:hiILl:m opt
|
||||
do case "$opt" in
|
||||
a)
|
||||
@@ -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
|
||||
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'
|
||||
@@ -179,10 +161,22 @@ Keeps a history of folders visited in ~/.bash_cdhistory
|
||||
d=$( grep $case -h ^"$1" ~/.qcd <( tac ~/.bash_cdhistory ) | head -n 1 )
|
||||
d=${d/*:/}
|
||||
if [ ! -z "$d" ]
|
||||
then \cd "$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
|
||||
@@ -201,7 +195,7 @@ function ncd() {
|
||||
fi
|
||||
if [ "$_iter_d" = "$_current_pwd" ]; then
|
||||
_current_found=true
|
||||
if [ "$1" = "-" ]; then
|
||||
if [ "$1" = "-" ]; then
|
||||
if [ -z "$_iter_prev" ]; then
|
||||
echo $_current_pwd was the first folder.
|
||||
else
|
||||
@@ -226,7 +220,7 @@ function scd() {
|
||||
return
|
||||
}
|
||||
local cdto cdfrom
|
||||
[[ -z "$2" ]] && {
|
||||
[[ -z "$2" ]] && {
|
||||
cdfrom="."
|
||||
} || {
|
||||
cdfrom="$2"
|
||||
@@ -243,7 +237,7 @@ function foldermenu_prompt {
|
||||
# Function to add in PS prompt variable, enabling foldermenu support
|
||||
[ -f .foldermenu ] && {
|
||||
foldermenu -lf 10 $@ || echo -n "*"
|
||||
} || {
|
||||
} || {
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -252,7 +246,7 @@ function igrep () {
|
||||
# Interactive grep, read grep arguments
|
||||
[[ "$1" = "-h" ]] && [[ "$#" -eq 1 ]] && {
|
||||
echo Interactive grep, read grep arguments
|
||||
return
|
||||
return
|
||||
}
|
||||
local args
|
||||
args="-i -e "
|
||||
@@ -271,7 +265,7 @@ function ised () {
|
||||
# Interactive sed
|
||||
[[ "$1" = "-h" ]] && [[ "$#" -eq 1 ]] && {
|
||||
echo Interactive sed, read sed arguments
|
||||
return
|
||||
return
|
||||
}
|
||||
local args
|
||||
if [ ! -f "$1" ]; then echo must give atleast one file; return 1;fi;
|
||||
@@ -315,9 +309,9 @@ function rmv () {
|
||||
function whenfilechanges() {
|
||||
# Run a command when file(s) time stamp changes
|
||||
echo "Version: 2015-10-13"
|
||||
[ -z "$2" ] && { echo 'Usage: whenfilechanges "file" "some" "command"
|
||||
Follows the modification time of the "file" and runs the command
|
||||
at every change.
|
||||
[ -z "$2" ] && { echo 'Usage: whenfilechanges "file" "some" "command"
|
||||
Follows the modification time of the "file" and runs the command
|
||||
at every change.
|
||||
The "file" may also be a glob e.g. "*tex" '
|
||||
return
|
||||
}
|
||||
@@ -327,7 +321,7 @@ function whenfilechanges() {
|
||||
local otime
|
||||
local ntime
|
||||
local i
|
||||
|
||||
|
||||
fname=($1)
|
||||
echo Waiting for ${#fname[@]} files to change: ${fname[@]}
|
||||
shift 1
|
||||
@@ -339,24 +333,23 @@ function whenfilechanges() {
|
||||
return
|
||||
}
|
||||
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 "$@"
|
||||
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 "$@"
|
||||
done
|
||||
}
|
||||
|
||||
# Shell enhancement
|
||||
@@ -397,7 +390,7 @@ function path_add_current {
|
||||
return
|
||||
}
|
||||
export PATH="${p}:$PATH"
|
||||
path_remove_duplicates
|
||||
path_remove_duplicates
|
||||
echo PATH=$PATH
|
||||
}
|
||||
function path_remove_duplicates {
|
||||
|
||||
Reference in New Issue
Block a user