blob: 2742f21b8a29daff63ed057aa66f344f158125c9 (
plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# dwb completion support.
__script() {
[[ -d ~/.config/dwb/userscripts/ ]] || return 0
files=( ~/.config/dwb/userscripts/*.js )
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
}
__profile() {
COMPREPLY=( $( compgen -W "$( while read line; do
[[ "$line" == \[* ]] && {
line="${line#\[}"
printf "${line%\]}"
} done < "${HOME}/.config/dwb/settings" )" -- $cur ) )
}
__session() {
local s p_found profile
s=${#COMP_WORDS[*]}
p_found=false
for (( i=1; i <= s; i++ )); do
$p_found && { profile=${COMP_WORDS[$i]}; break;}
[[ ${COMP_WORDS[$i]} == -p ]] ||\
[[ ${COMP_WORDS[$i]} == --profile ]] &&\
p_found=true
done
$p_found || profile=default
COMPREPLY=( $( compgen -W "$(
while read line; do
[[ "$line" == 'g:'* ]] && {
line="${line#g\:}"
printf "${line#\*} "
}
done < "${HOME}/.config/dwb/${profile}/session" )" -- $cur ) )
}
__execute() {
local cmds=""
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
}
__extension() {
COMPREPLY=( $( compgen -W "$( while read line; do
printf "${line% *} "
done < "${HOME}/.local/share/dwb/extensions/.metadata" )" -- $cur ) )
}
__get_installed() {
while read line; do
printf "${line% *} "
done < "${HOME}/.local/share/dwb/extensions/.installed"
}
__get_disabled() {
if [ -f "${HOME}/.config/dwb/userscripts/extension_loader.js" ]; then
while read line; do
if [[ "$line" == '/*<'*'__DISABLED' ]]; then
line="${line#/\*<}"
printf "${line%___DISABLED} "
fi
done < ${HOME}/.config/dwb/userscripts/extension_loader.js
fi
}
__installed_extension() {
COMPREPLY=( $( compgen -W "$(__get_installed)" -- $cur ) )
}
__disabled_extension() {
COMPREPLY=( $( compgen -W "$(__get_disabled)" -- $cur ) )
}
__enabled_extension() {
local disabled="$(__get_disabled)"
COMPREPLY=( $( compgen -W "$( for installed in $(__get_installed); do
[[ " ${disabled} " != *" ${installed} "* ]] && printf "${installed} "
done)" -- $cur ) )
}
_dwb() {
local cur prev opts lopts
_init_completion || return
opts="-h -c -e -f -l -n -r -R -p -x -v -S"
lopts="--help --check-script --embed --force --list-sessions --new-instance
--restore --override-restore --profile --execute --version --enable-scripts"
case "${prev}" in
-c|--check-script)
__script
return 0;;
-r|--restore)
__session
return 0;;
-p|--profile)
__profile
return 0;;
-x|--execute)
__execute
return 0;;
esac
case "${cur}" in
--*)
COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
return 0;;
-*)
COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
return 0;;
*)
_filedir
return 0;;
esac
} &&
complete -F _dwb dwb
_dwbem() {
local cur prev opts lopts
_init_completion || return
opts="-h -a -b -B -c -d -e -E -i -I -l -L -n -N -r -p -u -U"
lopts="--help --list-all --bind --setbind --config --disable --enable --edit
--install --info --list-installed --setload --no-config --no-confirm
--remove --proxy --upgrade --update"
extinstops=" -B --setbind -c --config -d --disable -e --enable -E --edit
-L --setload -r --remove -U --update "
extallops=" -i --install -I --info "
[[ " -d --disable " == *" ${prev} "* ]] && {
__enabled_extension
return 0
}
[[ " -e --enable " == *" ${prev} "* ]] && {
__disabled_extension
return 0
}
[[ "${extinstops}" == *" ${prev} "* ]] && {
__installed_extension
return 0
}
[[ "${extinstops}${extallops}" == *" ${prev} "* ]] && {
__extension
return 0
}
case "${cur}" in
--*)
COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
return 0;;
*)
COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
return 0;;
esac
} &&
complete -F _dwbem dwbem
# vim: set ft=sh:
|