Include trailing equals sign in options that take arguments that way.

This way it's clearer to users that an argument is expected.  It's
likely that this commit does not catch all such cases, but it should
do it for most of the affected commands I have installed.
This commit is contained in:
Ville Skyttä 2011-05-02 11:41:52 +03:00
parent 0a84ad771d
commit c875723bef
33 changed files with 103 additions and 57 deletions

View File

@ -774,11 +774,13 @@ _parse_help()
# Expand --[no]foo to --foo and --nofoo
if [[ $option == *\[no\]?* ]]; then
option2=${option/\[no\]/}
printf '%s\n' "${option2%%[=<{[]*}"
option2=${option2%%[<{[]*}
printf '%s\n' "${option2/=*/=}"
option=${option/\[no\]/no}
fi
printf '%s\n' "${option%%[=<{[]*}"
option=${option%%[<{[]*}
printf '%s\n' "${option/=*/=}"
done
}
@ -1678,8 +1680,9 @@ _longopt()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \
sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}\).*/\1/p' | sort -u )" \
sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}=\?\).*/\1/p' | sort -u )" \
-- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
elif [[ "$1" == @(mk|rm)dir ]]; then
compopt +o default
_filedir -d

View File

@ -61,6 +61,7 @@ _mock()
if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_filedir '@(?(no)src.r|s)pm'
fi

View File

@ -137,6 +137,7 @@ _yum()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&

View File

@ -60,27 +60,28 @@ _aspell()
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--conf --conf-dir --data-dir --dict-dir \
--encoding --add-filter --rem-filter --mode \
--add-extra-dicts --rem-extra-dicts \
--home-dir --ignore --ignore-accents \
COMPREPLY=( $( compgen -W '--conf= --conf-dir= --data-dir= --dict-dir= \
--encoding= --add-filter= --rem-filter= --mode= \
--add-extra-dicts= --rem-extra-dicts= \
--home-dir= --ignore= --ignore-accents \
--dont-ignore-accents --ignore-case --dont-ignore-case \
--ignore-repl --dont-ignore-repl --jargon --keyboard \
--lang --language-tag --local-data-dir --master \
--ignore-repl --dont-ignore-repl --jargon --keyboard= \
--lang= --language-tag --local-data-dir= --master= \
--module --add-module-search-order \
--rem-module-search-order --per-conf --personal \
--prefix --repl --run-together --dont-run-together \
--run-together-limit --run-together-min --save-repl \
--dont-save-repl --set-prefix --dont-set-prefix --size \
--rem-module-search-order --per-conf= --personal= \
--prefix= --repl= --run-together --dont-run-together \
--run-together-limit= --run-together-min= --save-repl \
--dont-save-repl --set-prefix --dont-set-prefix --size= \
--spelling --strip-accents --dont-strip-accents \
--sug-mode --add-word-list-path --rem-word-list-path \
--sug-mode= --add-word-list-path --rem-word-list-path \
--backup --dont-backup --reverse --dont-reverse \
--time --dont-time --keymapping --add-email-quote \
--rem-email-quote --email-margin --add-tex-command \
--rem-tex-command --tex-check-comments \
--time --dont-time --keymapping= --add-email-quote= \
--rem-email-quote= --email-margin= --add-tex-command= \
--rem-tex-command= --tex-check-comments \
--dont-tex-check-comments --add-tex-extension \
--rem-tex-extension --add-sgml-check --rem-sgml-check \
--rem-tex-extension --add-sgml-check= --rem-sgml-check= \
--add-sgml-extension --rem-sgml-extension' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
COMPREPLY=( $( compgen -W 'usage help check pipe list \
config soundslike filter version dump create merge' -- "$cur" ) )

View File

@ -30,6 +30,7 @@ _autoconf()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
@ -64,6 +65,7 @@ _autoreconf()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
@ -95,6 +97,7 @@ _autoscan()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -26,6 +26,7 @@ _automake()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
@ -62,6 +63,7 @@ _aclocal()
$split && return 0
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _aclocal aclocal aclocal-1.11

View File

@ -33,8 +33,10 @@ _configure()
awk '/^ --[A-Za-z]/ { print $1; \
if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' )" \
-- "$cur" ) )
[[ $COMPREPLY == *=* ]] && compopt -o nospace
else
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
fi
} &&
complete -F _configure configure

View File

@ -129,6 +129,7 @@ _mktemp()
local opts=$( _parse_help "$1" )
[[ $opts ]] || opts="-d -u -q -p -t" # non-GNU fallback
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
fi
} &&
complete -F _mktemp mktemp

View File

@ -33,6 +33,7 @@ _cryptsetup()
if [ -z $arg ]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
COMPREPLY=( $( compgen -W 'create remove status resize luksFormat \
luksOpen luksClose luksSuspend luksResume luksAddKey \

View File

@ -283,6 +283,7 @@ _cvs()
diff)
if [[ "$cur" == -* ]]; then
_cvs_command_options "$1" $mode
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
get_entries
COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) )

View File

@ -58,12 +58,12 @@ _dpkg()
COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
return 0
;;
*)
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
;;
esac
$split && return
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _dpkg dpkg dpkg-deb
}

View File

@ -68,6 +68,7 @@ _getent()
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
elif [[ -z $db ]]; then
COMPREPLY=( $( compgen -W 'passwd group hosts services protocols \
networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc \

View File

@ -16,6 +16,7 @@ _gzip()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" ) {-1..-9}' \
-- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -27,6 +27,7 @@ _iconv()
if [[ "$cur" = -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&

View File

@ -33,6 +33,7 @@ _info()
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi

View File

@ -493,7 +493,7 @@ have javaws &&
_javaws()
{
local cur prev words cword
_init_completion || return
_init_completion -n = || return
case $prev in
-help|-license|-about|-viewer|-arg|-param|-property|-update|-umask)
@ -509,8 +509,11 @@ _javaws()
;;
esac
if [[ $cur == -* ]]; then
if [[ $cur == *= ]]; then
return 0
elif [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W "$( _parse_help "$1" -help ) " -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -40,6 +40,7 @@ _k3b()
if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W "$( _parse_help "$1" )" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_filedir
fi

View File

@ -42,6 +42,7 @@ _man()
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -h )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi

View File

@ -27,6 +27,7 @@ _mc()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help-all )' \
-- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_filedir -d
fi

View File

@ -102,7 +102,7 @@ _mdadm()
local options
options='--help --help-options --version --verbose --quiet \
--brief --force --config --scan --metadata --homehost'
--brief --force --config= --scan --metadata= --homehost='
if [[ "$cur" == -* ]]; then
if [[ $cword -eq 1 ]] ; then
@ -111,18 +111,18 @@ _mdadm()
else
case ${words[cword-1]} in
-A|--assemble)
COMPREPLY=( $( compgen -W "$options --uuid \
--super-minor --name --force --run \
--no-degraded --auto --bitmap --backup-file \
--update --auto-update-homehost" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$options --uuid= \
--super-minor= --name= --force --run \
--no-degraded --auto= --bitmap= --backup-file= \
--update= --auto-update-homehost" -- "$cur" ) )
;;
-B|-C|-G|--build|--create|--grow)
COMPREPLY=( $( compgen -W "$options --raid-devices \
--spare-devices --size --chunk --rounding \
--level --layout --parity --bitmap \
--bitmap-chunk --write-mostly --write-behind \
--assume-clean --backup-file --name --run \
--force --auto" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$options --raid-devices= \
--spare-devices= --size= --chunk= --rounding= \
--level= --layout= --parity= --bitmap= \
--bitmap-chunk= --write-mostly --write-behind= \
--assume-clean --backup-file= --name= --run \
--force --auto=" -- "$cur" ) )
;;
-F|--follow|--monitor)
COMPREPLY=( $( compgen -W "$options --mail --program \
@ -142,6 +142,7 @@ _mdadm()
;;
esac
fi
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
cur=${cur:=/dev/}
_filedir

View File

@ -28,9 +28,10 @@ _mkinitrd()
COMPREPLY=( $( compgen -W '--version --help -v -f --preload \
--force-scsi-probe --omit-scsi-modules \
--omit-ide-modules --image-version --force-raid-probe \
--omit-raid-modules --with --force-lvm-probe \
--omit-raid-modules --with= --force-lvm-probe \
--omit-lvm-modules --builtin --omit-dmraid --net-dev \
--fstab --nocompress --dsdt --bootchart' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
local args
_count_args

View File

@ -49,6 +49,8 @@ _mysqladmin()
flush-logs flush-status flush-tables flush-threads flush-privileges \
kill password old-password ping processlist reload refresh shutdown \
status start-slave stop-slave variables version' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _mysqladmin mysqladmin

View File

@ -23,6 +23,7 @@ _mii_tool()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_available_interfaces -a
fi

View File

@ -23,6 +23,7 @@ _pkg_config()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
COMPREPLY=( $( compgen -W "$( pkg-config --list-all \
2>/dev/null | awk '{print $1}' )" -- "$cur" ) )

View File

@ -48,6 +48,7 @@ _createdb()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_pg_databases
fi
@ -80,6 +81,7 @@ _dropdb()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_pg_databases
fi
@ -126,6 +128,7 @@ _psql()
if [[ "$cur" == -* ]]; then
# return list of available options
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
# return list of available databases
_pg_databases

View File

@ -116,8 +116,8 @@ _rpm()
$split && return 0
# options common to all modes
local opts="--define --eval --macros --nodigest --nosignature --rcfile \
--quiet --pipe --verbose"
local opts="--define= --eval= --macros= --nodigest --nosignature \
--rcfile= --quiet --pipe --verbose"
case ${words[1]} in
-[iFU]*|--install|--freshen|--upgrade)
@ -125,10 +125,10 @@ _rpm()
COMPREPLY=( $( compgen -W "$opts --percent --force \
--test --replacepkgs --replacefiles --root \
--excludedocs --includedocs --noscripts --ignorearch \
--dbpath --prefix --ignoreos --nodeps --allfiles \
--dbpath --prefix= --ignoreos --nodeps --allfiles \
--ftpproxy --ftpport --justdb --httpproxy --httpport \
--noorder --relocate --badreloc --notriggers \
--excludepath --ignoresize --oldpackage \
--noorder --relocate= --badreloc --notriggers \
--excludepath= --ignoresize --oldpackage \
--queryformat --repackage --nosuggests" -- "$cur" ) )
else
_filedir '[rs]pm'
@ -148,7 +148,7 @@ _rpm()
opts+=" --changelog --configfiles --conflicts --docfiles
--dump --enhances --filesbypkg --filecaps --fileclass
--filecolor --fileprovide --filerequire --filesbypkg --info
--list --obsoletes --pipe --provides --queryformat --rcfile
--list --obsoletes --pipe --provides --queryformat=
--requires --scripts --suggests --triggers --xml"
if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
@ -175,7 +175,7 @@ _rpm()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --all --file --fileid
--dbpath --fscontext --ftswalk --group --hdrid --last
--package --pkgid --root --specfile --state
--package --pkgid --root= --specfile --state
--triggeredby --whatprovides --whatrequires" \
-- "$cur" ) )
elif [[ ${words[@]} != *\ -@(*([^ -])a|-all )* ]]; then
@ -193,7 +193,7 @@ _rpm()
;;
-[Vy]*|--verify)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --root --dbpath --nodeps \
COMPREPLY=( $( compgen -W "$opts --root= --dbpath --nodeps \
--nogroup --nolinkto --nomode --nomtime --nordev --nouser \
--nofiles --noscripts --nomd5 --querytags --specfile \
--whatrequires --whatprovides" -- "$cur" ) )
@ -216,13 +216,14 @@ _rpm()
;;
--import|--dbpath|--root)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--import --dbpath --root' \
COMPREPLY=( $( compgen -W '--import --dbpath --root=' \
-- "$cur" ) )
else
_filedir
fi
;;
esac
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
} &&
@ -271,6 +272,7 @@ _rpmbuild()
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W "$( _parse_help "$1" )" -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -167,6 +167,7 @@ _chpasswd()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
@ -193,6 +194,7 @@ _newusers()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
@ -234,6 +236,7 @@ _groupadd()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
@ -258,6 +261,7 @@ _groupmod()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
@ -382,6 +386,7 @@ _faillog()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
@ -407,6 +412,7 @@ _lastlog()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&

View File

@ -154,10 +154,12 @@ _smartctl()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version --info --all --xall
--scan --scan-open --quietmode --device --tolerance --badsum
--report --nocheck --smart --offlineauto --saveauto --health
--capabilities --attributes --log --vendorattribute --firmwarebug
--presets --drivedb --test --captive --abort' -- "$cur" ) )
--scan --scan-open --quietmode= --device= --tolerance= --badsum=
--report= --nocheck= --smart= --offlineauto= --saveauto= --health
--capabilities --attributes --log= --vendorattribute=
--firmwarebug= --presets= --drivedb= --test= --captive --abort' \
-- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
cur=${cur:=/dev/}
_filedir

View File

@ -116,15 +116,12 @@ _sysbench()
fi
done
# Long options need the "=" (whitespace split doesn't work), so we
# include it in completions that require a value.
local opts="--num-threads= --max-requests= --max-time= --thread-stack-size=
--init-rng= --debug= --validate= --help --version"
if [[ $test ]]; then
local help=( $( _parse_help "$1" "--test=$test help" ) )
opts+=" ${help[@]/%/=} prepare run cleanup help version"
opts+=" ${help[@]} prepare run cleanup help version"
else
opts+=" --test="
fi

View File

@ -29,6 +29,7 @@ _wol()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -21,6 +21,7 @@ _wvdial()
case $cur in
-*)
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
;;
*)
# start with global and personal config files

View File

@ -9,6 +9,7 @@ _xz()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" --long-help ) {-1..-9}' \
-- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
@ -62,6 +63,7 @@ _xzdec()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi

View File

@ -50,15 +50,15 @@ assert_bash_list "-one" $cmd "internal dash 2"
sync_after_int
set cmd {fn() { printf '%s\n' "--long-arg=value"; }; _parse_help fn}
assert_bash_list "--long-arg" $cmd "value stripped"
assert_bash_list "--long-arg=" $cmd "value stripped"
sync_after_int
set cmd {fn() { printf '%s\n' "--long-arg=-value"; }; _parse_help fn}
assert_bash_list "--long-arg" $cmd "value not seen as option"
assert_bash_list "--long-arg=" $cmd "value not seen as option"
sync_after_int
set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn}
assert_bash_list "--long-arg" $cmd "two options with values"
assert_bash_list "--long-arg=" $cmd "two options with values"
sync_after_int
set cmd {fn() { printf '%s\n' "-m,--mirror"; }; _parse_help fn}
@ -82,11 +82,11 @@ assert_bash_list "--foo" $cmd "long with value and eq sign in brackets"
sync_after_int
set cmd {fn() { printf '%s\n' "--foo=<bar>"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "long with value in angle brackets"
assert_bash_list "--foo=" $cmd "long with value in angle brackets"
sync_after_int
set cmd {fn() { printf '%s\n' "--foo={bar,quux}"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "long with value in curly brackets"
assert_bash_list "--foo=" $cmd "long with value in curly brackets"
sync_after_int
set cmd {fn() { printf '%s\n' "--[no]foo"; }; _parse_help fn}