-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcompletions.bash
32 lines (27 loc) · 892 Bytes
/
completions.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
#
# Enable the bash completions by simply sourcing this file
# and configuring APP to your app's name, e.g.
#
# $ APP=my-app source /path/to/clingon/extras/completions.bash
#
APP=${APP:-$(basename ${BASH_SOURCE})}
function _clingon_app_completions() {
local cur prev words cword
_init_completion -s || return
local _suggestions=$( "${words[@]:0:${cword}}" --bash-completions )
local _options=$( grep -E '^-' <<<${_suggestions} )
local _sub_commands=$( grep -v -E '^-' <<<${_suggestions} )
if [[ "${cur}" == "-"* ]]; then
# Options only
COMPREPLY=( $(compgen -W "${_options}" -- "${cur}") )
else
# Sub-commands only
COMPREPLY=( $(compgen -W "${_sub_commands}" -- "${cur}") )
fi
}
complete -o bashdefault \
-o default \
-o nospace \
-F _clingon_app_completions ${APP}
unset APP