diff --git a/bash_completion b/bash_completion index e8128666..f66fa3e1 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.576 2003/06/07 22:59:37 ianmacd Exp $ +# $Id: bash_completion,v 1.577 2003/06/07 23:09:34 ianmacd Exp $ # # Copyright (C) Ian Macdonald # @@ -1302,14 +1302,14 @@ _rpm() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} options="" - ver=$(rpm --version); ver=${ver##* } + ver=$(rpm --version); ver=${ver##* } - if [[ "$ver" > "4.0.4" ]]; then - options="--nodigest" - fi - if [[ "$ver" > "4.0.99" ]]; then - options="$options --nosignature" - fi + if [[ "$ver" > "4.0.4" ]]; then + options="--nodigest" + fi + if [[ "$ver" > "4.0.99" ]]; then + options="$options --nosignature" + fi if [ $COMP_CWORD -eq 1 ]; then # first parameter on line @@ -2484,16 +2484,19 @@ fi # _command() { - local cur func cline cspec noglob + local cur func cline cspec noglob IFS=$' \t\n' cmd COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} + cmd=${COMP_WORDS[1]} if [ $COMP_CWORD -eq 1 ]; then + IFS=$'\n\t' COMPREPLY=( $( compgen -c -- $cur ) ) - elif complete -p ${COMP_WORDS[1]} &>/dev/null; then - cspec=$( complete -p ${COMP_WORDS[1]} ) - if [ "${cspec#*-F }" != "$cspec" ]; then + IFS=$' \t\n' + elif complete -p $cmd &>/dev/null; then + cspec=$( complete -p $cmd ) + if [ "${cspec#* -F }" != "$cspec" ]; then # complete -F # # COMP_CWORD and COMP_WORDS() are not read-only, @@ -2516,26 +2519,31 @@ _command() COMP_WORDS=( $cline ) # reset noglob if necessary [ $noglob -eq 1 ] && shopt -uo noglob - $func $cline + # this is needed in case user finished entering command and pressed tab (e.g. sudo ls ) + COMP_CWORD=$(( $COMP_CWORD > 0 ? $COMP_CWORD : 1 )) + cur=${COMP_WORDS[COMP_CWORD]} + _COMMAND_FUNC=$func + _COMMAND_FUNC_ARGS=( $cmd $2 $3 ) + COMP_LINE=$cline + COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 )) + $func $cmd $2 $3 # remove any \: generated by a command that doesn't # default to filenames or dirnames (e.g. sudo chown) if [ "${cspec#*-o }" != "$cspec" ]; then cspec=${cspec#*-o } cspec=${cspec%% *} if [[ "$cspec" != @(dir|file)names ]]; then - COMPREPLY=( "${COMPREPLY[@]//\\\\:/:}" ) + IFS=$'\n\t' + COMPREPLY=( ${COMPREPLY[@]//\\\\:/:} ) + IFS=$' \t\n' fi fi - elif [ "${cspec#*-[abcdefgjkvu]}" != "$cspec" ]; then - # complete -[abcdefgjkvu] - func=$( echo $cspec | \ - sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' ) - COMPREPLY=( $( compgen $func -- $cur ) ) - elif [ "${cspec#*-A}" != "$cspec" ]; then - # complete -A - func=${cspec#*-A } - func=${func%% *} - COMPREPLY=( $( compgen -A $func -- $cur ) ) + elif [ -n "$cspec" ]; then + cspec=${cspec#complete}; + cspec=${cspec%%$cmd}; + IFS=$'\n\t' + COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) ); + IFS=$' \t\n' fi fi @@ -2546,7 +2554,7 @@ complete -F _command $filenames nohup exec nice eval strace time ltrace then \ _root_command() { - PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 + PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3 } complete -F _root_command $filenames sudo fakeroot @@ -4731,11 +4739,11 @@ _dict() case "$prev" in -@(d|-database|i|info)) - COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) return 0 ;; -@(s|-strategy)) - COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) return 0 ;; *)