Skip to content

Commit

Permalink
_init_completion: Add -s for splitting long options, use it in comple…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
scop committed May 1, 2011
1 parent 41ce815 commit a54857c
Show file tree
Hide file tree
Showing 46 changed files with 186 additions and 426 deletions.
18 changes: 10 additions & 8 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,15 @@ _split_longopt()
# Initialize completion and deal with redirections: do file completion where
# appropriate, and adjust prev, words, and cword as if no redirections exist
# so that completions do not need to deal with them. Before calling this
# function, make sure cur, prev, words, and cword are local.
# function, make sure cur, prev, words, and cword are local, ditto split if
# you use -s.
#
# Options:
# -n EXCLUDE Passed to _get_comp_words_by_ref -n with redirection chars
# -e XSPEC Passed to _filedir as first arg for stderr redirections
# -o XSPEC Passed to _filedir as first arg for other output redirections
# -i XSPEC Passed to _filedir as first arg for stdin redirections
# -s Split long options with _split_longopt, implies -n =
# @return True (0) if completion needs further processing,
# False (> 0) if tilde is followed by a valid username, completions
# are put in COMPREPLY and no further processing is necessary.
Expand All @@ -685,12 +687,13 @@ _init_completion()
{
local exclude flag outx errx inx OPTIND=1

while getopts "n:e:o:i:" flag "$@"; do
while getopts "n:e:o:i:s" flag "$@"; do
case $flag in
n) exclude=$OPTARG ;;
n) exclude+=$OPTARG ;;
e) errx=$OPTARG ;;
o) outx=$OPTARG ;;
i) inx=$OPTARG ;;
s) split=false ; exclude+== ;;
esac
done

Expand Down Expand Up @@ -739,6 +742,8 @@ _init_completion()
done
[[ $cword -ge 1 ]] && prev=${words[cword-1]} || prev=

[[ $split ]] && _split_longopt && split=true

return 0
}

Expand Down Expand Up @@ -1639,11 +1644,8 @@ _complete_as_root()

_longopt()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "${prev,,}" in
--*dir*)
Expand Down
7 changes: 2 additions & 5 deletions completions/_mock
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ have mock || return

_mock()
{
local cur prev words cword
_init_completion -n = || return
local cur prev words cword split
_init_completion -s || return

local plugins='tmpfs root_cache yum_cache bind_mount ccache'
local cfgdir=/etc/mock count=0 i
Expand All @@ -23,9 +23,6 @@ _mock()
count=$((++count))
done

local split=false
_split_longopt && split=true

case $prev in
-h|--help|--copyin|--copyout|--arch|-D|--define|--with|--without|\
--uniqueext|--rpmbuild_timeout|--sources|--cwd)
Expand Down
7 changes: 2 additions & 5 deletions completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ _yum_plugins()

_yum()
{
local cur prev words cword
_init_completion -n = || return
local cur prev words cword split
_init_completion -s || return

local special i
for (( i=0; i < ${#words[@]}-1; i++ )); do
Expand Down Expand Up @@ -75,9 +75,6 @@ _yum()
esac
fi

local split=false
_split_longopt && split=true

case $prev in
list)
COMPREPLY=( $( compgen -W 'all available updates \
Expand Down
7 changes: 5 additions & 2 deletions completions/_yum-utils
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ have repomanage || return

_repomanage()
{
local cur prev words cword
_init_completion || return
local cur prev words cword split
_init_completion -s || return

[[ "$prev" == -@(h|-help|k|-keep) ]] && return 0

$split && return

if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_filedir -d
fi
Expand Down
7 changes: 2 additions & 5 deletions completions/aspell
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ _aspell_dictionary()

_aspell()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
-c|-p|check|--conf|--personal|--repl|--per-conf)
Expand Down
21 changes: 6 additions & 15 deletions completions/autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
have autoconf &&
_autoconf()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|-h|--version|-V|--trace|-t)
Expand Down Expand Up @@ -43,11 +40,8 @@ complete -F _autoconf autoconf
have autoreconf || have autoheader &&
_autoreconf()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|-h|--version|-V)
Expand Down Expand Up @@ -84,11 +78,8 @@ complete -F _autoreconf autoreconf autoheader
have autoscan || have autoupdate &&
_autoscan()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|-h|--version|-V)
Expand Down
14 changes: 4 additions & 10 deletions completions/automake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
have automake &&
_automake()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|--version)
Expand Down Expand Up @@ -39,11 +36,8 @@ complete -F _automake automake automake-1.11
have aclocal &&
_aclocal()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|--print-ac-dir|--version)
Expand Down
14 changes: 4 additions & 10 deletions completions/bluez
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ _bluetooth_packet_types()

_hcitool()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
-i)
Expand Down Expand Up @@ -113,11 +110,8 @@ complete -F _hcitool hcitool

_sdptool()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
--bdaddr)
Expand Down
7 changes: 2 additions & 5 deletions completions/chkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ have chkconfig || return

_chkconfig()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
--level=[1-6]|[1-6]|--list|--add|--del|--override)
Expand Down
7 changes: 2 additions & 5 deletions completions/configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

_configure()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
--*prefix|--*dir)
Expand Down
21 changes: 6 additions & 15 deletions completions/coreutils
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
have chown &&
_chown()
{
local cur prev words cword
local cur prev words cword split
# Don't treat user:group as separate words.
_init_completion -n := || return

local split=false
_split_longopt && split=true
_init_completion -s -n : || return

case "$prev" in
--from)
Expand Down Expand Up @@ -55,14 +52,11 @@ complete -F _chown chown
have chgrp &&
_chgrp()
{
local cur prev words cword
_init_completion -n = || return
local cur prev words cword split
_init_completion -s || return

cur=${cur//\\\\/}

local split=false
_split_longopt && split=true

if [[ "$prev" == --reference ]]; then
_filedir
return 0
Expand Down Expand Up @@ -116,11 +110,8 @@ complete -F _id id
have mktemp &&
_mktemp()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case "$prev" in
--help|--version|--suffix)
Expand Down
7 changes: 2 additions & 5 deletions completions/cpio
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ _cpio_format()

_cpio()
{
local cur prev words cword
_init_completion -n := || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s -n : || return

# --name value style option
case $prev in
Expand Down
7 changes: 2 additions & 5 deletions completions/cppcheck
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ have cppcheck || return

_cppcheck()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
--append|--exitcode-suppressions|--file-list|--rule-file|\
Expand Down
7 changes: 2 additions & 5 deletions completions/cryptsetup
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ _cryptsetup_device()

_cryptsetup()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

case $prev in
--key-file|--master-key-file|--header-backup-file|-d)
Expand Down
6 changes: 2 additions & 4 deletions completions/dpkg
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ _comp_dpkg_installed_packages()
#
_dpkg()
{
local cur prev words cword
_init_completion -n = || return
local cur prev words cword split
_init_completion -s || return

_expand || return 0

_split_longopt

local i=$cword

# find the last option flag
Expand Down
7 changes: 2 additions & 5 deletions completions/getent
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ have getent || return

_getent()
{
local cur prev words cword
_init_completion -n = || return

local split=false
_split_longopt && split=true
local cur prev words cword split
_init_completion -s || return

local i db
for (( i=1; i < cword; i++ )); do
Expand Down
8 changes: 3 additions & 5 deletions completions/heimdal
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ _heimdal_encodings()

_ktutil()
{
local cur prev words cword
_init_completion -n = || return
local cur prev words cword split
_init_completion -s || return

local command options split=false

_split_longopt && split=true
local command options

case $prev in
-p|--principal)
Expand Down
Loading

0 comments on commit a54857c

Please sign in to comment.