diff options
Diffstat (limited to 'completions/dict')
-rw-r--r-- | completions/dict | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/completions/dict b/completions/dict index 4cfdf98f..a31816d3 100644 --- a/completions/dict +++ b/completions/dict @@ -1,6 +1,5 @@ -# dict(1) completion +# dict(1) completion -*- shell-script -*- -{ have dict || have rdict; } && { _dictdata() { dict $host $port $1 2>/dev/null | sed -ne \ @@ -9,26 +8,25 @@ _dictdata() _dict() { - local cur prev host port db dictfile + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev - dictfile=/usr/share/dict/words + local host port db i - for (( i=1; i < COMP_CWORD; i++ )); do - case ${COMP_WORDS[i]} in + for (( i=1; i < cword; i++ )); do + case ${words[i]} in -h|--host) - host=${COMP_WORDS[i+1]} + host=${words[i+1]} [ -n "$host" ] && host="-h $host" i=$((++i)) ;; -p|--port) - port=${COMP_WORDS[i+1]} + port=${words[i+1]} [ -n "$port" ] && port="-p $port" i=$((++i)) ;; -d|--database) - db=${COMP_WORDS[i+1]} + db=${words[i+1]} [ -n "$db" ] && host="-d $db" i=$((++i)) ;; @@ -38,14 +36,7 @@ _dict() done if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W '--host --port --database \ - --match --strategy --config \ - --nocorrect --dbs --strats \ - --serverhelp --info --serverinfo \ - --noauth --user --key --version \ - --license --help --verbose --raw \ - --pager --debug --html --pipesize --client' \ - -- "$cur" ) ) + COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) return 0 fi @@ -62,16 +53,10 @@ _dict() ;; esac + local dictfile=/usr/share/dict/words [ -r $dictfile ] && \ COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) ) -} +} && complete -F _dict -o default dict rdict -} -# Local variables: -# mode: shell-script -# sh-basic-offset: 4 -# sh-indent-comment: t -# indent-tabs-mode: nil -# End: # ex: ts=4 sw=4 et filetype=sh |