Make wtf bash < 4 compatible, fix -f handling.

This commit is contained in:
Ville Skyttä 2009-10-21 20:27:58 +03:00
parent 474896f2c8
commit cdc0bcc3c1

View File

@ -11,9 +11,20 @@ _wtf()
prev=${COMP_WORDS[COMP_CWORD-1]}
[ "$prev" = -f ] && _filedir && return 0
[[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0
db=${ACRONYMDB:-/usr/share/misc/acronyms*}
COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db )" -- "${cur^^}" ) )
set -- "${COMP_WORDS[@]}"
while [ $# -gt 0 ]; do
if [ "$1" = -f ]; then
shift ; db=$1 ; break
fi
shift
done
[ -z $db ] && db=${ACRONYMDB:-/usr/share/misc/acronyms*}
[ ${BASH_VERSINFO[0]} -ge 4 ] && cur="${cur^^}"
COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur}" ) )
} &&
complete -F _wtf $filenames wtf