Skip to content

Commit

Permalink
ifup etc: Add option and option argument completion
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 19, 2018
1 parent daf010a commit f499aa3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 23 additions & 2 deletions completions/ifup
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@ _ifupdown()
local cur prev words cword
_init_completion || return

if [[ $cword -eq 1 ]]; then
case $prev in
--help|--version|--allow|--exclude|--option|-!(-*)[hVXo])
return
;;
--interfaces|-!(-*)i)
_filedir
return
;;
--state-dir)
_filedir -d
return
;;
esac

if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return
fi

local args
_count_args "" "@(--allow|-i|--interfaces|--state-dir|-X|--exclude|-o)"

if [[ $args -eq 1 ]]; then
_configured_interfaces
COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
fi

} &&
complete -F _ifupdown ifup ifdown ifquery ifstatus

Expand Down
3 changes: 3 additions & 0 deletions test/lib/completions/ifup.exp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if {[info exists ::env(CI)]} {
} else {
assert_complete_any "ifup "
sync_after_int

assert_complete_any "ifup --"
sync_after_int
}

assert_no_complete "ifup bash-completion "
Expand Down

0 comments on commit f499aa3

Please sign in to comment.