-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaudi-bash.completions.bash
122 lines (101 loc) · 3.3 KB
/
gaudi-bash.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# shellcheck shell=bash
cite about-completion
about-completion 'Gaudi bash completions'
_gaudi-bash-comp-list-available-not-enabled () {
subdirectory="$1"
local available_things
available_things=$(for f in $(compgen -G "${GAUDI_BASH}/components/$subdirectory/lib/*.bash" | sort -d);
do
file_entity=$(basename "$f")
local enabled_components
enabled_components=$(command ls "${GAUDI_BASH}/components/enabled/"[0-9]*$GAUDI_BASH_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1)
if [[ -z "$enabled_components" ]]
then
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g'
fi
done)
COMPREPLY=( $(compgen -W "all ${available_things}" -- ${CURRENT}) )
}
_gaudi-bash-comp-list-enabled () {
local subdirectory="$1"
local enabled_things
enabled_things=$(for f in $(sort -d <(compgen -G "${GAUDI_BASH}/components/enabled/*.$subdirectory.bash") <(compgen -G "${GAUDI_BASH}/components/enabled/*.$subdirectory.bash"));
do
basename "$f" | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*___//g"
done)
COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${CURRENT}) )
}
_gaudi-bash-comp-list-available () {
subdirectory="$1"
local enabled_things
enabled_things=$(for f in $(compgen -G "${GAUDI_BASH}/components/$subdirectory/lib/*.bash" | sort -d);
do
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g'
done)
COMPREPLY=( $(compgen -W "${enabled_things}" -- ${CURRENT}) )
}
_gaudi-bash-comp () {
local BASE_OPTIONS="show enable disable reload restart search update backup doctor help version"
local CURRENT PREVIOUS
COMPREPLY=()
CURRENT="${COMP_WORDS[COMP_CWORD]}"
PREVIOUS="${COMP_WORDS[COMP_CWORD - 1]}"
verb="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}"
case "${verb}" in
show)
local show_args="aliases completions plugins"
COMPREPLY=( $(compgen -W "${show_args}" -- ${CURRENT}) )
return 0
;;
help)
if [[ x"${PREVIOUS}" == x"aliases" ]]; then
_gaudi-bash-comp-list-available aliases
return 0
else
local help_args="aliases completions plugins"
COMPREPLY=( $(compgen -W "${help_args}" -- ${CURRENT}) )
return 0
fi
;;
doctor)
local doctor_args="errors warnings all"
COMPREPLY=( $(compgen -W "${doctor_args}" -- ${CURRENT}) )
return 0
;;
reload | search | update | version)
return 0
;;
enable | disable)
if [[ x"${verb}" == x"enable" ]];then
suffix="available-not-enabled"
else
suffix="enabled"
fi
case "${file_type}" in
alias)
_gaudi-bash-comp-list-${suffix} aliases
return 0
;;
plugin)
_gaudi-bash-comp-list-${suffix} plugins
return 0
;;
completion)
_gaudi-bash-comp-list-${suffix} completions
return 0
;;
*)
local enable_disable_args="alias completion plugin"
COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${CURRENT}) )
return 0
;;
esac
;;
esac
COMPREPLY=( $(compgen -W "${BASE_OPTIONS}" -- ${CURRENT}) )
return 0
}
# Activate completion for gaudi-bash and its common misspellings
complete -F _gaudi-bash-comp gaudi-bash
complete -F _gaudi-bash-comp gudi-bash