-
Notifications
You must be signed in to change notification settings - Fork 84
/
pihole-updatelists.bash
51 lines (40 loc) · 1.21 KB
/
pihole-updatelists.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
#!/usr/bin/env bash
# https://unix.stackexchange.com/a/55622
_pihole_updatelists()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --no-gravity --no-reload --verbose --debug --config= --env --git-branch= --update --rollback --version"
case "${prev}" in
"--version")
opts="--git-branch="
;;
"--update")
opts="--force --git-branch= --yes"
;;
"--rollback")
opts="--yes"
;;
esac
if [[ ${prev} == "--"* && ${cur} == "=" ]] ; then
compopt -o filenames
COMPREPLY=(*)
return 0
fi
if [[ ${prev} == '=' ]] ; then
cur=${cur//\\ / }
[[ ${cur} == "~/"* ]] && cur=${cur/\~/$HOME}
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != "--"*"=" ]] ; then
compopt +o nospace
fi
return 0
}
complete -o nospace -F _pihole_updatelists pihole-updatelists