-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdexcctl.bash-completion
50 lines (41 loc) · 1.54 KB
/
dexcctl.bash-completion
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# bash programmable completion for dexcctl
# copy to /etc/bash_completion.d and restart your shell session
# Copyright (c) by Andreas M. Antonopoulos
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
_dexcctl() {
local cur prev words=() cword
local dexcctl
# dexcctl might not be in $PATH
dexcctl="$1"
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev words cword
case "$cur" in
-*=*) # prevent nonsense completions
return 0
;;
*)
local helpopts globalcmds
# get the global options, starting with -
if [[ "$cur" =~ ^- ]]; then
globalcmds=$($dexcctl -h 2>&1 | awk '$1 ~ /^-[a-zA-Z]/ { sub(/,/, ""); print $1}')
fi
# get the global options, starting with --
if [[ "$cur" =~ ^-- ]]; then
globalcmds=$($dexcctl -h 2>&1 | awk '$1 ~ /^--/ { sub(/,/, ""); print $1}'; dexcctl -h 2>&1 | awk '$2 ~ /^--/ { sub(/,/, ""); print $2}')
fi
# get the regular commands
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
helpopts=$($dexcctl -l 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }' )
fi
COMPREPLY=( $( compgen -W "$helpopts $globalcmds" -X "*," -- "$cur" ) )
esac
} &&
complete -F _dexcctl dexcctl
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh