From c987f95b25c13c4625794e1c9db5bfdf317dd663 Mon Sep 17 00:00:00 2001 From: ianmacd <> Date: Tue, 15 Apr 2003 06:54:50 +0000 Subject: [PATCH] - move dict completion into main file and rewrite from scratch --- bash_completion | 76 +++++++++++++++++++++++++++++++++++++++++++++++-- contrib/dict | 30 ------------------- 2 files changed, 74 insertions(+), 32 deletions(-) delete mode 100644 contrib/dict diff --git a/bash_completion b/bash_completion index cbf644e6..42144bde 100644 --- a/bash_completion +++ b/bash_completion @@ -1,6 +1,6 @@ # bash_completion - some programmable completion functions for bash 2.05b # -# $Id: bash_completion,v 1.543 2003/04/14 09:42:09 ianmacd Exp $ +# $Id: bash_completion,v 1.544 2003/04/15 08:54:50 ianmacd Exp $ # # Copyright (C) Ian Macdonald # @@ -649,7 +649,7 @@ _renice() command=$1 i=0 - # walk back throuh command line and find last option + # walk back through command line and find last option while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do curopt=${COMP_WORDS[COMP_CWORD-$i]} case "$curopt" in @@ -4597,6 +4597,78 @@ _iconv() } [ -n "${have:-}" ] && complete -F _iconv $default iconv +# dict(1) completion +# +{ have dict || have rdict; } && +_dictdata() +{ + dict $host $port $1 2>/dev/null | sed -ne \ + 's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p' +} + +# dict(1) completion +# +_dict() +{ + local cur prev host port db dictfile + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + dictfile=/usr/share/dict/words + + for (( i=1; i < COMP_CWORD; i++ )); do + case "${COMP_WORDS[i]}" in + -@(h|--host)) + host=${COMP_WORDS[i+1]} + [ -n "$host" ] && host="-h $host" + i=$((++i)) + ;; + -@(p|-port)) + port=${COMP_WORDS[i+1]} + [ -n "$port" ] && port="-p $port" + i=$((++i)) + ;; + -@(d|-database)) + db=${COMP_WORDS[i+1]} + [ -n "$db" ] && host="-d $db" + i=$((++i)) + ;; + *) + ;; + esac + done + + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \ + -m --match -s --strategy -c --config -C \ + --nocorrect -D --dbs -S --strats -H \ + --serverhelp -i --info -I --serverinfo \ + -a --noauth -u --user -k --key -V --version \ + -L --license --help -v --verbose -r --raw \ + -P --pager --debug --html --pipesize --client' \ + -- "$cur" ) ) + return 0 + fi + + case "$prev" in + -@(d|-database|i|info)) + COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) + return 0 + ;; + -@(s|-strategy)) + COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) + return 0 + ;; + *) + ;; + esac + + [ -r $dictfile ] && \ + COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) ) +} +[ -n "${have:-}" ] && complete -F _dict $default dict rdict + _filedir_xspec() { local IFS cur xspec diff --git a/contrib/dict b/contrib/dict deleted file mode 100644 index 4a0d1d52..00000000 --- a/contrib/dict +++ /dev/null @@ -1,30 +0,0 @@ -# dict completion by Alex Shinn - -_dict() -{ - local cur DICTFILE - - COMPREPLY=() - cur=${COMP_WORDS[COMP_CWORD]} - DICTFILE=/usr/share/dict/words - - case "$cur" in - --*) - COMPREPLY=( $( compgen -W '--help --version --verbose \ - --host --port --database --match --strategy \ - --config --nocorrect --dbs --starts --serverhelp \ - --info --serverinfo --noauth --user --key --license \ - --raw --pager --debug --pipesize --client' -- $cur ) ) - ;; - -*) - COMPREPLY=( $( compgen -W '-h -p -d -m -s -c -C -D -S \ - -H -i -I -a -u -k -V -L -v -r -P' $cur ) ) - ;; - *) - COMPREPLY=( $( compgen -W '$( cat $DICTFILE )' -- $cur ) ) - ;; - esac - - return 0 -} -complete -F _dict dict