From cdc0bcc3c1176a4f2925e2944593ca5c3eb89870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 21 Oct 2009 20:27:58 +0300 Subject: [PATCH] Make wtf bash < 4 compatible, fix -f handling. --- contrib/wtf | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/contrib/wtf b/contrib/wtf index c1d19a64..4744e5f1 100644 --- a/contrib/wtf +++ b/contrib/wtf @@ -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