*: Invoke command to be completed, not its basename

This commit is contained in:
Ville Skyttä 2014-11-16 12:18:41 +02:00
parent 7d66285b42
commit 7d3de619d1
19 changed files with 40 additions and 40 deletions

View File

@ -105,7 +105,7 @@ _7z()
else else
if [[ ${words[1]} == d ]]; then if [[ ${words[1]} == d ]]; then
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( printf '%s\n' $( 7z l ${words[2]} \ COMPREPLY=( $( compgen -W "$( printf '%s\n' $( $1 l ${words[2]} \
-slt 2>/dev/null | sed -n '/^Path =/s/^Path = \(.*\)$/\1/p' \ -slt 2>/dev/null | sed -n '/^Path =/s/^Path = \(.*\)$/\1/p' \
2>/dev/null | tail -n+2 ) )" -- "$cur" ) ) 2>/dev/null | tail -n+2 ) )" -- "$cur" ) )
compopt -o filenames compopt -o filenames

View File

@ -22,12 +22,12 @@ _abook()
case $prev in case $prev in
--informat) --informat)
COMPREPLY=( $( compgen -W "$(abook --formats | \ COMPREPLY=( $( compgen -W "$($1 --formats | \
sed -n -e 's/^'$'\t''\([a-z]*\).*/\1/p' -e '/^$/q')" -- "$cur" ) ) sed -n -e 's/^'$'\t''\([a-z]*\).*/\1/p' -e '/^$/q')" -- "$cur" ) )
return 0 return 0
;; ;;
--outformat) --outformat)
COMPREPLY=( $( compgen -W "$(abook --formats | \ COMPREPLY=( $( compgen -W "$($1 --formats | \
sed -n -e '/^$/,$s/^'$'\t''\([a-z]*\).*/\1/p')" -- "$cur" ) ) sed -n -e '/^$/,$s/^'$'\t''\([a-z]*\).*/\1/p')" -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -18,7 +18,7 @@ _brctl()
show) show)
;; ;;
*) *)
COMPREPLY=( $( compgen -W "$(brctl show | \ COMPREPLY=( $( compgen -W "$($1 show | \
awk 'NR>1 {print $1}' )" -- "$cur" ) ) awk 'NR>1 {print $1}' )" -- "$cur" ) )
esac esac
;; ;;

View File

@ -10,22 +10,22 @@ _cvsps()
return 0 return 0
;; ;;
-s) -s)
COMPREPLY=( $( compgen -W "$( cvsps 2>/dev/null | COMPREPLY=( $( compgen -W "$( $1 2>/dev/null |
awk '/^PatchSet:?[ \t]/ { print $2 }' )" -- "$cur" ) ) awk '/^PatchSet:?[ \t]/ { print $2 }' )" -- "$cur" ) )
return 0 return 0
;; ;;
-a) -a)
COMPREPLY=( $( compgen -W "$( cvsps 2>/dev/null | COMPREPLY=( $( compgen -W "$( $1 2>/dev/null |
awk '/^Author:[ \t]/ { print $2 }' )" -- "$cur" ) ) awk '/^Author:[ \t]/ { print $2 }' )" -- "$cur" ) )
return 0 return 0
;; ;;
-b) -b)
COMPREPLY=( $( compgen -W "$( cvsps 2>/dev/null | COMPREPLY=( $( compgen -W "$( $1 2>/dev/null |
awk '/^Branch:[ \t]/ { print $2 }' )" -- "$cur" ) ) awk '/^Branch:[ \t]/ { print $2 }' )" -- "$cur" ) )
return 0 return 0
;; ;;
-r) -r)
COMPREPLY=( $( compgen -W "$( cvsps 2>/dev/null | COMPREPLY=( $( compgen -W "$( $1 2>/dev/null |
awk '/^Tag:[ \t]+[^(]/ { print $2 }' )" -- "$cur" ) ) awk '/^Tag:[ \t]+[^(]/ { print $2 }' )" -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -42,12 +42,12 @@ _getent()
return 0 return 0
;; ;;
protocols|networks|ahosts|ahostsv4|ahostsv6|rpc) protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)
COMPREPLY=( $( compgen -W "$( getent $db | \ COMPREPLY=( $( compgen -W "$( $1 $db | \
awk '{ print $1 }' )" -- "$cur" ) ) awk '{ print $1 }' )" -- "$cur" ) )
return 0 return 0
;; ;;
aliases|shadow|gshadow) aliases|shadow|gshadow)
COMPREPLY=( $( compgen -W "$( getent $db | cut -d: -f1 )" \ COMPREPLY=( $( compgen -W "$( $1 $db | cut -d: -f1 )" \
-- "$cur" ) ) -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -12,13 +12,13 @@ _gpg()
;; ;;
--export|--sign-key|--lsign-key|--nrsign-key|--nrlsign-key|--edit-key) --export|--sign-key|--lsign-key|--nrsign-key|--nrlsign-key|--edit-key)
# return list of public keys # return list of public keys
COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 --list-keys 2>/dev/null | \
sed -ne 's@^pub.*/\([^ ]*\).*$@\1@p' \ sed -ne 's@^pub.*/\([^ ]*\).*$@\1@p' \
-ne 's@^.*\(<\([^>]*\)>\).*$@\2@p' )" -- "$cur" ) ) -ne 's@^.*\(<\([^>]*\)>\).*$@\2@p' )" -- "$cur" ) )
return 0 return 0
;; ;;
-r|--recipient) -r|--recipient)
COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 --list-keys 2>/dev/null | \
sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ) ) sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ) )
if [[ -e ~/.gnupg/gpg.conf ]]; then if [[ -e ~/.gnupg/gpg.conf ]]; then
COMPREPLY+=( $( compgen -W "$( sed -ne \ COMPREPLY+=( $( compgen -W "$( sed -ne \
@ -30,7 +30,7 @@ _gpg()
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$(gpg --dump-options)' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$($1 --dump-options)' -- "$cur" ) )
fi fi
} && } &&
complete -F _gpg -o default gpg complete -F _gpg -o default gpg

View File

@ -16,13 +16,13 @@ _gpg2()
;; ;;
--export|--sign-key|--lsign-key|--nrsign-key|--nrlsign-key|--edit-key) --export|--sign-key|--lsign-key|--nrsign-key|--nrlsign-key|--edit-key)
# return list of public keys # return list of public keys
COMPREPLY=( $( compgen -W "$( gpg2 --list-keys 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 --list-keys 2>/dev/null | \
sed -ne 's@^pub.*/\([^ ]*\).*$@\1@p' \ sed -ne 's@^pub.*/\([^ ]*\).*$@\1@p' \
-ne 's@^.*\(<\([^>]*\)>\).*$@\2@p' )" -- "$cur" ) ) -ne 's@^.*\(<\([^>]*\)>\).*$@\2@p' )" -- "$cur" ) )
return 0 return 0
;; ;;
-r|--recipient) -r|--recipient)
COMPREPLY=( $( compgen -W "$( gpg2 --list-keys 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 --list-keys 2>/dev/null | \
sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ) ) sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ) )
if [[ -e ~/.gnupg/gpg.conf ]]; then if [[ -e ~/.gnupg/gpg.conf ]]; then
COMPREPLY+=( $( compgen -W "$( sed -ne \ COMPREPLY+=( $( compgen -W "$( sed -ne \
@ -34,7 +34,7 @@ _gpg2()
esac esac
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$(gpg2 --dump-options)' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$($1 --dump-options)' -- "$cur" ) )
fi fi
} && } &&
complete -F _gpg2 -o default gpg2 complete -F _gpg2 -o default gpg2

View File

@ -23,19 +23,19 @@ _gphoto2()
return 0 return 0
;; ;;
--port) --port)
COMPREPLY=( $(compgen -W "$( gphoto2 --list-ports 2>/dev/null | \ COMPREPLY=( $(compgen -W "$( $1 --list-ports 2>/dev/null | \
tail -n +4 | awk '{ print $1 }' )" -- "$cur") ) tail -n +4 | awk '{ print $1 }' )" -- "$cur") )
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
return 0 return 0
;; ;;
--camera) --camera)
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $(compgen -W "$( gphoto2 --list-cameras 2>/dev/null | \ COMPREPLY=( $(compgen -W "$( $1 --list-cameras 2>/dev/null | \
tail -n +3 | awk -F'"' '{ print $2 }' )" -- "$cur") ) tail -n +3 | awk -F'"' '{ print $2 }' )" -- "$cur") )
return 0 return 0
;; ;;
--get-config|--set-config|--set-config-index|--set-config-value) --get-config|--set-config|--set-config-index|--set-config-value)
COMPREPLY=( $(compgen -W "$( gphoto2 --list-config 2>/dev/null \ COMPREPLY=( $(compgen -W "$( $1 --list-config 2>/dev/null \
)" -- "$cur") ) )" -- "$cur") )
return 0 return 0
;; ;;

View File

@ -11,7 +11,7 @@ _ipv6calc()
;; ;;
-I|--in|-O|--out|-A|--action) -I|--in|-O|--out|-A|--action)
# With ipv6calc < 0.73.0, -m does nothing here, so use sed instead. # With ipv6calc < 0.73.0, -m does nothing here, so use sed instead.
COMPREPLY=( $( compgen -W "$( ipv6calc "$prev" -h 2>&1 | \ COMPREPLY=( $( compgen -W "$( $1 "$prev" -h 2>&1 | \
sed -ne 's/^[[:space:]]\{1,\}\([^[:space:]:]\{1,\}\)[[:space:]]*:.*/\1/p' )" \ sed -ne 's/^[[:space:]]\{1,\}\([^[:space:]:]\{1,\}\)[[:space:]]*:.*/\1/p' )" \
-- "$cur" ) ) -- "$cur" ) )
return 0 return 0

View File

@ -12,23 +12,23 @@ _mcrypt()
return 0 return 0
;; ;;
-o|--keymode) -o|--keymode)
COMPREPLY=( $( compgen -W '$( mcrypt --list-keymodes \ COMPREPLY=( $( compgen -W '$( $1 --list-keymodes \
2>/dev/null )' -- "$cur" ) ) 2>/dev/null )' -- "$cur" ) )
return 0 return 0
;; ;;
-m|--mode) -m|--mode)
COMPREPLY=( $( compgen -W "$( mcrypt --list \ COMPREPLY=( $( compgen -W "$( $1 --list \
2>/dev/null | sed -e 's/.*: //' -e 's/ $//' | \ 2>/dev/null | sed -e 's/.*: //' -e 's/ $//' | \
sort -u )" -- "$cur" ) ) sort -u )" -- "$cur" ) )
return 0 return 0
;; ;;
-a|--algorithm) -a|--algorithm)
COMPREPLY=( $( compgen -W "$( mcrypt --list 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 --list 2>/dev/null | \
awk '{print $1}' )" -- "$cur" ) ) awk '{print $1}' )" -- "$cur" ) )
return 0 return 0
;; ;;
-h|--hash) -h|--hash)
COMPREPLY=( $( compgen -W '$( mcrypt --list-hash 2>/dev/null | \ COMPREPLY=( $( compgen -W '$( $1 --list-hash 2>/dev/null | \
sed -e 1d )' -- "$cur" ) ) sed -e 1d )' -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -15,7 +15,7 @@ _medusa()
return 0 return 0
;; ;;
-M) -M)
COMPREPLY=( $( compgen -W "$(medusa -d | awk '/^ +\+/ {print $2}' \ COMPREPLY=( $( compgen -W "$($1 -d | awk '/^ +\+/ {print $2}' \
| sed -e 's/\.mod$//')" ) ) | sed -e 's/\.mod$//')" ) )
return 0 return 0
;; ;;

View File

@ -51,7 +51,7 @@ _mount()
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )
elif [[ ! -e /etc/fstab ]]; then elif [[ ! -e /etc/fstab ]]; then
# probably Cygwin # probably Cygwin
COMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$( $1 | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )
else else
# probably BSD # probably BSD
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) )

View File

@ -7,13 +7,13 @@ _msynctool()
case $words in case $words in
--configure) --configure)
COMPREPLY=( $( compgen -W "$(msynctool --showgroup \ COMPREPLY=( $( compgen -W "$($1 --showgroup \
$prev | awk '/^Member/ {print $2}' | sed \ $prev | awk '/^Member/ {print $2}' | sed \
-e 's/:$//' )" -- "$cur" ) ) -e 's/:$//' )" -- "$cur" ) )
return 0 return 0
;; ;;
--addmember) --addmember)
COMPREPLY=( $( compgen -W '$(msynctool --listplugins \ COMPREPLY=( $( compgen -W '$($1 --listplugins \
| sed -e '1d' )' -- "$cur" ) ) | sed -e '1d' )' -- "$cur" ) )
return 0 return 0
;; ;;
@ -21,12 +21,12 @@ _msynctool()
case $prev in case $prev in
--configure|--addgroup|--delgroup|--showgroup|--sync|--addmember) --configure|--addgroup|--delgroup|--showgroup|--sync|--addmember)
COMPREPLY=( $( compgen -W '$(msynctool --listgroups \ COMPREPLY=( $( compgen -W '$($1 --listgroups \
| sed -e '1d' )' -- "$cur" ) ) | sed -e '1d' )' -- "$cur" ) )
return 0 return 0
;; ;;
--showformats|--filter-objtype|--slow-sync) --showformats|--filter-objtype|--slow-sync)
COMPREPLY=( $( compgen -W '$(msynctool --listobjects \ COMPREPLY=( $( compgen -W '$($1 --listobjects \
| sed -e '1d' )' -- "$cur" ) ) | sed -e '1d' )' -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -89,7 +89,7 @@ _openssl()
return 0 return 0
;; ;;
-cipher) -cipher)
COMPREPLY=( $( IFS=: compgen -W "$( openssl ciphers )" \ COMPREPLY=( $( IFS=: compgen -W "$( $1 ciphers )" \
-- "$cur" ) ) -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -35,7 +35,7 @@ _pkg_config()
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY == *= ]] && compopt -o nospace
else else
COMPREPLY=( $( compgen -W "$( pkg-config --list-all \ COMPREPLY=( $( compgen -W "$( $1 --list-all \
2>/dev/null | awk '{print $1}' )" -- "$cur" ) ) 2>/dev/null | awk '{print $1}' )" -- "$cur" ) )
fi fi
} && } &&

View File

@ -26,17 +26,17 @@ _qemu()
return 0 return 0
;; ;;
-soundhw) -soundhw)
COMPREPLY=( $( compgen -W "$( qemu -soundhw ? | awk \ COMPREPLY=( $( compgen -W "$( $1 -soundhw ? | awk \
'/^[[:lower:]]/ {print $1}' ) all" -- "$cur" ) ) '/^[[:lower:]]/ {print $1}' ) all" -- "$cur" ) )
return 0 return 0
;; ;;
-M) -M)
COMPREPLY=( $( compgen -W "$( qemu -M ? | awk \ COMPREPLY=( $( compgen -W "$( $1 -M ? | awk \
'/^[[:lower:]]/ {print $1}' )" -- "$cur" ) ) '/^[[:lower:]]/ {print $1}' )" -- "$cur" ) )
return 0 return 0
;; ;;
-cpu) -cpu)
COMPREPLY=( $( compgen -W "$( qemu -cpu ? | awk \ COMPREPLY=( $( compgen -W "$( $1 -cpu ? | awk \
'{print $2}' )" -- "$cur" ) ) '{print $2}' )" -- "$cur" ) )
return 0 return 0
;; ;;
@ -82,7 +82,7 @@ _qemu()
return 0 return 0
;; ;;
-watchdog) -watchdog)
COMPREPLY=( $( compgen -W "$( qemu -watchdog ? 2>&1 | \ COMPREPLY=( $( compgen -W "$( $1 -watchdog ? 2>&1 | \
awk '{print $1}' )" -- "$cur" ) ) awk '{print $1}' )" -- "$cur" ) )
return 0 return 0
;; ;;

View File

@ -15,7 +15,7 @@ _rfkill()
;; ;;
2) 2)
if [[ $prev == block || $prev == unblock ]]; then if [[ $prev == block || $prev == unblock ]]; then
COMPREPLY=( $( compgen -W "$(rfkill list | awk -F: \ COMPREPLY=( $( compgen -W "$($1 list | awk -F: \
'/^[0-9]/ {print $1}') all wifi bluetooth uwb wimax \ '/^[0-9]/ {print $1}') all wifi bluetooth uwb wimax \
wwan gps" -- "$cur" ) ) wwan gps" -- "$cur" ) )
fi fi

View File

@ -191,7 +191,7 @@ _svk()
--delete' -- "$cur" ) ) --delete' -- "$cur" ) )
;; ;;
sync) sync)
COMPREPLY=( $( compgen -W "$( svk mirror --list \ COMPREPLY=( $( compgen -W "$( $1 mirror --list \
2>/dev/null | awk '/^\//{print $1}' )" -- "$cur" ) ) 2>/dev/null | awk '/^\//{print $1}' )" -- "$cur" ) )
;; ;;
co|checkout|push|pull) co|checkout|push|pull)
@ -200,7 +200,7 @@ _svk()
else else
path=// path=//
fi fi
COMPREPLY=( $( compgen -W "$( svk list $path 2>/dev/null | \ COMPREPLY=( $( compgen -W "$( $1 list $path 2>/dev/null | \
sed -e 's|\(.*\)|'$path'\1|')" -- "$cur" ) ) sed -e 's|\(.*\)|'$path'\1|')" -- "$cur" ) )
;; ;;
*) *)

View File

@ -7,7 +7,7 @@ _xfreerdp()
case $prev in case $prev in
-k) -k)
COMPREPLY=( $( compgen -W "$(xfreerdp --kbd-list | \ COMPREPLY=( $( compgen -W "$($1 --kbd-list | \
awk '/^0x/ {print $1}')" -- "$cur" ) ) awk '/^0x/ {print $1}')" -- "$cur" ) )
return 0 return 0
;; ;;