Cleanups: Make code more compact.

Drop useless spaces, backslashes, return codes, unused arguments etc.
This commit is contained in:
Igor Murzov 2011-11-20 17:00:03 +03:00
parent 03c2fe9301
commit f0283e1c1b
17 changed files with 154 additions and 159 deletions

View File

@ -1625,7 +1625,7 @@ _command_offset()
for (( i; i <= COMP_CWORD; i++ )); do for (( i; i <= COMP_CWORD; i++ )); do
unset COMP_WORDS[i] unset COMP_WORDS[i]
done done
COMP_CWORD=$(( $COMP_CWORD - $word_offset )) ((COMP_CWORD -= $word_offset))
COMPREPLY=() COMPREPLY=()
local cur local cur
@ -1696,7 +1696,7 @@ _root_command()
{ {
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
local root_command=$1 local root_command=$1
_command $1 $2 $3 _command
} }
complete -F _root_command fakeroot gksu gksudo kdesudo really sudo complete -F _root_command fakeroot gksu gksudo kdesudo really sudo

View File

@ -28,7 +28,7 @@ _fbgs()
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '-l -xl -xxl -a --fitwidth -d -m -t -g -f -p \ COMPREPLY=( $(compgen -W '-l -xl -xxl -a --fitwidth -d -m -t -g -f -p
-h -c' -- "$cur") ) -h -c' -- "$cur") )
[[ $COMPREPLY ]] && return [[ $COMPREPLY ]] && return
fi fi

View File

@ -36,12 +36,11 @@ _fbi()
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '--help --version --store --list --text \ COMPREPLY=( $(compgen -W '--help --version --store --list --text
--autozoom --autoup --noautoup --autodown --noautodown --fitwidth \ --autozoom --{,no}autoup --{,no}autodown --{,no}fitwidth
--nofitwidth --verbose --noverbose --random --norandom --comments \ --{,no}verbose --{,no}random --{,no}comments --{,no}edit
--nocomments --edit --noedit --backup --nobackup --preserve \ --{,no}backup --{,no}preserve --{,no}readahead --cachemem --blend
--nopreserve --readahead --noreadahead --cachemem --blend --vt \ --vt --scroll --timeout --{,no}once --resolution --gamma --font
--scroll --timeout --once --noonce --resolution --gamma --font \
--device --mode' -- "$cur") ) --device --mode' -- "$cur") )
[[ $COMPREPLY ]] && return [[ $COMPREPLY ]] && return
fi fi

View File

@ -8,29 +8,29 @@ _kcov()
case "$prev" in case "$prev" in
--pid|-p) --pid|-p)
_pids _pids
return 0 return
;; ;;
--sort-type|-s) --sort-type|-s)
COMPREPLY=( $(compgen -W 'filename percentage' -- "$cur") ) COMPREPLY=( $(compgen -W 'filename percentage' -- "$cur") )
return 0 return
;; ;;
--include-path|--exclude-path) --include-path|--exclude-path)
_filedir _filedir
return 0 return
;; ;;
--limits|-l|--title|-t|--include-pattern|--exclude-pattern|\ --limits|-l|--title|-t|--include-pattern|--exclude-pattern|\
--path-strip-level) --path-strip-level)
# argument required but no completions available # argument required but no completions available
return 0 return
;; ;;
esac esac
$split && return 0 $split && return
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") ) COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY == *= ]] && compopt -o nospace
return 0 return
fi fi
_filedir _filedir

View File

@ -4,15 +4,14 @@ _removepkg()
{ {
local cur prev words cword local cur prev words cword
_init_completion || return _init_completion || return
if [[ $cur == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-copy -keep -preserve -warn' \ COMPREPLY=( $(compgen -W '-copy -keep -preserve -warn' -- "$cur") )
-- "$cur" ) ) return
return 0
fi fi
if [[ $cur == */* ]]; then if [[ "$cur" == */* ]]; then
_filedir _filedir
return 0 return
fi fi
local root=${ROOT:-/} local root=${ROOT:-/}

View File

@ -7,10 +7,10 @@ _rpm2tgz()
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '-s -S -n -r -d -c' -- "$cur") ) COMPREPLY=( $(compgen -W '-s -S -n -r -d -c' -- "$cur") )
return 0 return
fi fi
COMPREPLY=( $(compgen -f -X "!*.rpm" -- "$cur") ) _filedir "rpm"
} && complete -F _rpm2tgz -o plusdirs rpm2tgz rpm2txz rpm2targz } && complete -F _rpm2tgz rpm2tgz rpm2txz rpm2targz
# ex: ts=4 sw=4 et filetype=sh # ex: ts=4 sw=4 et filetype=sh

View File

@ -6,33 +6,33 @@ _sbopkg()
_init_completion || return _init_completion || return
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-b -c -d -e -f -g -h -i -k -l \ COMPREPLY=( $(compgen -W '-b -c -d -e -f -g -h -i -k -l -o
-o -P -p -q -R -r -s -u -V -v' -- "$cur" ) ) -P -p -q -R -r -s -u -V -v' -- "$cur") )
return 0 return
fi fi
case "$prev" in case "$prev" in
-e) -e)
COMPREPLY=( $(compgen -W 'ask continue stop' -- "$cur") ) COMPREPLY=( $(compgen -W 'ask continue stop' -- "$cur") )
return 0 return
;; ;;
-f) -f)
_filedir _filedir
return 0 return
;; ;;
-d) -d)
_filedir -d _filedir -d
return 0 return
;; ;;
-V) -V)
COMPREPLY=( $(compgen -W "? \ COMPREPLY=( $(compgen -W "? \
$(sbopkg -V ? 2>&1 | cut -s -f1)" -- "$cur") ) $(sbopkg -V ? 2>&1 | cut -s -f1)" -- "$cur") )
return 0 return
;; ;;
-i|-b) -i|-b)
;; ;;
*) *)
return 0 return
;; ;;
esac esac
@ -45,8 +45,8 @@ _sbopkg()
fi fi
done done
if [[ ! -r $config ]]; then if [[ ! -r "$config" ]]; then
return 0 return
fi fi
. $config . $config
@ -64,7 +64,7 @@ _sbopkg()
done done
if [[ ! -r $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT ]]; then if [[ ! -r $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT ]]; then
return 0 return
fi fi
COMPREPLY=( $(sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}"\ COMPREPLY=( $(sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}"\
$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT) $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT)

View File

@ -17,34 +17,34 @@ _slackpkg()
-delall|-checkmd5|-checkgpg|-checksize|-postinst|-onoff|-download_all|\ -delall|-checkmd5|-checkgpg|-checksize|-postinst|-onoff|-download_all|\
-dialog|-batch|-only_new_dotnew|-use_includes|-spinning) -dialog|-batch|-only_new_dotnew|-use_includes|-spinning)
COMPREPLY=( $(compgen -W 'on off' -- "$cur") ) COMPREPLY=( $(compgen -W 'on off' -- "$cur") )
return 0 return
;; ;;
-default_answer) -default_answer)
COMPREPLY=( $(compgen -W 'yes no' -- "$cur") ) COMPREPLY=( $(compgen -W 'yes no' -- "$cur") )
return 0 return
;; ;;
-dialog_maxargs|-mirror) -dialog_maxargs|-mirror)
# argument required but no completions available # argument required but no completions available
return 0 return
;; ;;
esac esac
$split && return 0 $split && return
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
compopt -o nospace compopt -o nospace
COMPREPLY=( $( compgen -W '-delall= -checkmd5= -checkgpg= \ COMPREPLY=( $(compgen -W '-delall= -checkmd5= -checkgpg=
-checksize= -postinst= -onoff= -download_all= -dialog= \ -checksize= -postinst= -onoff= -download_all= -dialog=
-dialog_maxargs= -batch= -only_new_dotnew= -use_includes= \ -dialog_maxargs= -batch= -only_new_dotnew= -use_includes=
-spinning= -default_answer= -mirror=' -- "$cur") ) -spinning= -default_answer= -mirror=' -- "$cur") )
return 0 return
fi fi
local confdir="/etc/slackpkg" local confdir="/etc/slackpkg"
local config="$confdir/slackpkg.conf" local config="$confdir/slackpkg.conf"
if [[ ! -r $config ]]; then if [[ ! -r "$config" ]]; then
return 0 return
fi fi
. "$config" . "$config"
@ -59,7 +59,7 @@ _slackpkg()
case "$action" in case "$action" in
generate-template|search|file-search) generate-template|search|file-search)
# argument required but no completions available # argument required but no completions available
return 0 return
;; ;;
install-template|remove-template) install-template|remove-template)
if [[ -e $confdir/templates ]]; then if [[ -e $confdir/templates ]]; then
@ -67,39 +67,39 @@ _slackpkg()
compgen -f -X "!*.template" -- "$cur") ) compgen -f -X "!*.template" -- "$cur") )
COMPREPLY=( ${COMPREPLY[@]%.template} ) COMPREPLY=( ${COMPREPLY[@]%.template} )
fi fi
return 0 return
;; ;;
remove) remove)
_filedir _filedir
COMPREPLY+=( $( compgen -W 'a ap d e f k kde kdei l n t tcl x \ COMPREPLY+=( $(compgen -W 'a ap d e f k kde kdei l n t tcl x
xap y' -- "$cur") ) xap y' -- "$cur") )
COMPREPLY+=( $(cd /var/log/packages; compgen -f -- "$cur") ) COMPREPLY+=( $(cd /var/log/packages; compgen -f -- "$cur") )
return 0 return
;; ;;
install|reinstall|upgrade|blacklist|download) install|reinstall|upgrade|blacklist|download)
_filedir _filedir
COMPREPLY+=( $( compgen -W 'a ap d e f k kde kdei l n t tcl x \ COMPREPLY+=( $(compgen -W 'a ap d e f k kde kdei l n t tcl x
xap y' -- "$cur") ) xap y' -- "$cur") )
COMPREPLY+=( $( cut -f 6 -d\ ${WORKDIR}/pkglist 2> /dev/null | \ COMPREPLY+=( $(cut -f 6 -d\ "${WORKDIR}/pkglist" 2> /dev/null | \
grep "^$cur") ) grep "^$cur") )
return 0 return
;; ;;
info) info)
COMPREPLY+=( $( cut -f 6 -d\ ${WORKDIR}/pkglist 2> /dev/null | \ COMPREPLY=( $(cut -f 6 -d\ "${WORKDIR}/pkglist" 2> /dev/null | \
grep "^$cur") ) grep "^$cur") )
return 0 return
;; ;;
update) update)
# we should complete the same as the next `list` + "gpg" # we should complete the same as the next `list` + "gpg"
COMPREPLY=( $(compgen -W 'gpg' -- "$cur") ) COMPREPLY=( $(compgen -W 'gpg' -- "$cur") )
;& ;&
*) *)
COMPREPLY+=( $( compgen -W 'install reinstall upgrade remove \ COMPREPLY+=( $(compgen -W 'install reinstall upgrade remove
blacklist download update install-new upgrade-all \ blacklist download update install-new upgrade-all
clean-system new-config check-updates help generate-template \ clean-system new-config check-updates help generate-template
install-template remove-template search file-search info' -- \ install-template remove-template search file-search info' -- \
"$cur") ) "$cur") )
return 0 return
;; ;;
esac esac

View File

@ -8,18 +8,18 @@ _slapt_get()
case "$prev" in case "$prev" in
--config|-c) --config|-c)
_filedir _filedir
return 0 return
;; ;;
--retry|--search) --retry|--search)
# argument required but no completions available # argument required but no completions available
return 0 return
;; ;;
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") ) COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY == *= ]] && compopt -o nospace
[[ $COMPREPLY ]] && return 0 [[ $COMPREPLY ]] && return
fi fi
local i t local i t
@ -48,7 +48,7 @@ _slapt_get()
break break
fi fi
done done
if [[ ! -r $config ]]; then if [[ ! -r "$config" ]]; then
return return
fi fi
@ -59,21 +59,21 @@ _slapt_get()
local name=${cur%%-*} local name=${cur%%-*}
COMPREPLY=( $(slapt-get -c $config --search "^$name" 2>/dev/null |\ COMPREPLY=( $(slapt-get -c $config --search "^$name" 2>/dev/null |\
sed -ne "/^$cur/{s/ .*$//;p}") ) sed -ne "/^$cur/{s/ .*$//;p}") )
return 0 return
;; ;;
avl) # --install|-i| avl) # --install|-i|
COMPREPLY=( $(slapt-get -c $config --available 2>/dev/null | \ COMPREPLY=( $(slapt-get -c $config --available 2>/dev/null | \
sed -ne "/^$cur/{s/ .*$//;p}") ) sed -ne "/^$cur/{s/ .*$//;p}") )
return 0 return
;; ;;
ins) # --remove|--filelist ins) # --remove|--filelist
COMPREPLY=( $(cd /var/log/packages; compgen -f -- "$cur") ) COMPREPLY=( $(cd /var/log/packages; compgen -f -- "$cur") )
return 0 return
;; ;;
set) # --install-set set) # --install-set
COMPREPLY=( $( compgen -W 'a ap d e f k kde kdei l n t tcl x \ COMPREPLY=( $(compgen -W 'a ap d e f k kde kdei l n t tcl x
xap y' -- "$cur") ) xap y' -- "$cur") )
return 0 return
;; ;;
esac esac
} && complete -F _slapt_get slapt-get } && complete -F _slapt_get slapt-get

View File

@ -8,18 +8,18 @@ _slapt_src()
case "$prev" in case "$prev" in
--config|-c) --config|-c)
_filedir _filedir
return 0 return
;; ;;
--search|-s|--postprocess|-p) --search|-s|--postprocess|-p)
# argument required but no completions available # argument required but no completions available
return 0 return
;; ;;
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") ) COMPREPLY=( $(compgen -W '$(_parse_help "$1" --help)' -- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY == *= ]] && compopt -o nospace
[[ $COMPREPLY ]] && return 0 [[ $COMPREPLY ]] && return
fi fi
local i t local i t
@ -31,7 +31,7 @@ _slapt_src()
fi fi
done done
if [[ $t != all ]]; then if [[ $t != all ]]; then
return 0 return
fi fi
local config="/etc/slapt-get/slapt-srcrc" # default config location local config="/etc/slapt-get/slapt-srcrc" # default config location
@ -42,18 +42,18 @@ _slapt_src()
break break
fi fi
done done
if [[ ! -r $config ]]; then if [[ ! -r "$config" ]]; then
return 0 return
fi fi
if [[ "$cur" == *:* ]]; then if [[ "$cur" == *:* ]]; then
local name=${cur%:*} local name=${cur%:*}
local version=${cur##*:} local version=${cur##*:}
COMPREPLY=( $( slapt-src --config $config --search "^$name" 2> \ COMPREPLY=( $(slapt-src --config "$config" --search "^$name" 2> \
/dev/null | sed -ne "/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p}") ) /dev/null | sed -ne "/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p}") )
else else
COMPREPLY=( $( slapt-src --config $config --search "^$cur" 2>/dev/null \ COMPREPLY=( $(slapt-src --config "$config" --search "^$cur" 2> \
| sed -ne "/^$cur/{s/ .*$//;p}" ) ) /dev/null | sed -ne "/^$cur/{s/ .*$//;p}") )
fi fi
} && complete -F _slapt_src slapt-src } && complete -F _slapt_src slapt-src

View File

@ -6,9 +6,9 @@ _upgradepkg()
_init_completion || return _init_completion || return
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--dry-run --install-new --reinstall \ COMPREPLY=( $(compgen -W '--dry-run --install-new --reinstall
--verbose' -- "$cur") ) --verbose' -- "$cur") )
return 0 return
fi fi
if [[ "$cur" == ?*%* ]]; then if [[ "$cur" == ?*%* ]]; then
@ -20,7 +20,7 @@ _upgradepkg()
[[ $COMPREPLY ]] || nofiles=1 [[ $COMPREPLY ]] || nofiles=1
COMPREPLY+=( $(compgen -P "$prev%" -S '/' -d -- "$cur") ) COMPREPLY+=( $(compgen -P "$prev%" -S '/' -d -- "$cur") )
[[ $nofiles ]] && compopt -o nospace [[ $nofiles ]] && compopt -o nospace
return 0 return
fi fi
_filedir "t[bglx]z" _filedir "t[bglx]z"

View File

@ -5,7 +5,7 @@ _wine()
local cur prev words cword local cur prev words cword
_init_completion || return _init_completion || return
if [[ "$cword" -eq 1 ]]; then if [[ $cword -eq 1 ]]; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W '--help --version' -- "$cur") ) COMPREPLY=( $(compgen -W '--help --version' -- "$cur") )
[[ $COMPREPLY ]] && return [[ $COMPREPLY ]] && return

View File

@ -33,7 +33,8 @@ _xgamma()
local t screens=$(xrandr --query 2>/dev/null | sed -n \ local t screens=$(xrandr --query 2>/dev/null | sed -n \
-e '/^Screen /s|^Screen \{1,\}\(.*\):.*$|\1|p' 2>/dev/null) -e '/^Screen /s|^Screen \{1,\}\(.*\):.*$|\1|p' 2>/dev/null)
t="${cur#:}" t="${cur#:}"
COMPREPLY=( $(compgen -P "${t%.*}." -W "$screens" -- "${cur##*.}")) COMPREPLY=( $(compgen -P "${t%.*}." -W "$screens" -- \
"${cur##*.}") )
elif [[ "$cur" != *:* ]]; then elif [[ "$cur" != *:* ]]; then
# complete hostnames # complete hostnames
_known_hosts_real -c "$cur" _known_hosts_real -c "$cur"

View File

@ -10,8 +10,6 @@ _xhost ()
-*) _known_hosts_real -p- "${cur:1}" ;; -*) _known_hosts_real -p- "${cur:1}" ;;
*) _known_hosts_real "$cur" ;; *) _known_hosts_real "$cur" ;;
esac esac
return 0
} && } &&
complete -F _xhost xhost complete -F _xhost xhost

View File

@ -7,15 +7,15 @@ _xrandr()
local output modes local output modes
case $prev in case "$prev" in
--output|--left-of|--right-of|--above|--below|--same-as) --output|--left-of|--right-of|--above|--below|--same-as)
local outputs=$(xrandr|awk '/connected/ {print $1}') local outputs=$(xrandr|awk '/connected/ {print $1}')
COMPREPLY=( $(compgen -W "$outputs" -- "$cur") ) COMPREPLY=( $(compgen -W "$outputs" -- "$cur") )
return 0 return
;; ;;
--mode) --mode)
for(( i = 1; i < cword; i++ )); do for(( i = 1; i < cword; i++ )); do
if [[ "${words[i]}" == "--output" ]]; then if [[ "${words[i]}" == --output ]]; then
output=${words[i+1]} output=${words[i+1]}
break break
fi fi
@ -23,36 +23,34 @@ _xrandr()
modes=$(xrandr|sed -e "1,/$output/ d" \ modes=$(xrandr|sed -e "1,/$output/ d" \
-e "/connected/,$ d"|awk '{print $1}') -e "/connected/,$ d"|awk '{print $1}')
COMPREPLY=( $(compgen -W "$modes" -- "$cur") ) COMPREPLY=( $(compgen -W "$modes" -- "$cur") )
return 0 return
;; ;;
-o|--orientation) -o|--orientation)
COMPREPLY=( $(compgen -W 'normal inverted left right 0 1 2 3' -- \ COMPREPLY=( $(compgen -W 'normal inverted left right 0 1 2 3' -- \
"$cur") ) "$cur") )
return 0 return
;; ;;
--reflect) --reflect)
COMPREPLY=( $( compgen -W 'normal x y xy' -- \ COMPREPLY=( $(compgen -W 'normal x y xy' -- "$cur") )
"$cur" ) ) return
return 0
;; ;;
--rotate) --rotate)
COMPREPLY=( $( compgen -W 'normal inverted left right' -- \ COMPREPLY=( $(compgen -W 'normal inverted left right' -- "$cur") )
"$cur" ) ) return
return 0
;; ;;
esac esac
case $cur in case $cur in
*) *)
COMPREPLY=( $(compgen -W '-display -help --orientation --query \ COMPREPLY=( $(compgen -W '-display -help --orientation --query
--size --rate --version -x -y --screen --verbose --dryrun \ --size --rate --version -x -y --screen --verbose --dryrun
--q1 --q12 --nograb --prop --properties --fb --fbmm --dpi \ --q1 --q12 --nograb --prop --properties --fb --fbmm --dpi
--output --auto --mode --preferred --pos --rate --refresh \ --output --auto --mode --preferred --pos --rate --refresh
--reflect --rotate --left-of --right-of --above --below \ --reflect --rotate --left-of --right-of --above --below
--same-as --set --scale --transform --off --crtc --panning \ --same-as --set --scale --transform --off --crtc --panning
--gamma --brightness --primary --noprimary --newmode --rmmode \ --gamma --brightness --primary --noprimary --newmode --rmmode
--addmode --delmode' -- "$cur") ) --addmode --delmode' -- "$cur") )
return 0 return
;; ;;
esac esac
} && } &&