Repository navigation
Expand file tree
/
Copy pathnsite-completion.bash
More file actions
55 lines (50 loc) · 1.83 KB
/
Copy pathnsite-completion.bash
File metadata and controls
55 lines (50 loc) · 1.83 KB
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
# shellcheck shell=bash
# bash completion for nsite — add to ~/.bashrc:
# source /path/to/nsite-completion.bash
_nsite_sites() {
find /etc/nginx/sites-enabled -maxdepth 1 \( -type l -o -type f \) -printf '%f\n' 2>/dev/null
}
_nsite_php_versions() {
local dir
for dir in /etc/php/*/fpm; do
if [[ -d "$dir" ]]; then
basename "$(dirname "$dir")"
fi
done
}
_nsite() {
local cur cmd
cur="${COMP_WORDS[COMP_CWORD]}"
cmd="${COMP_WORDS[1]:-}"
if [[ $COMP_CWORD -eq 1 ]]; then
mapfile -t COMPREPLY < <(compgen -W "add rm list php logs doctor secure unsecure domain config help" -- "$cur")
return
fi
case "$cmd" in
rm|logs|secure|unsecure|domain)
mapfile -t COMPREPLY < <(compgen -W "$(_nsite_sites)" -- "$cur")
;;
add)
mapfile -t COMPREPLY < <(compgen -W "--php --root --proxy --tld --force --dry-run" -- "$cur")
;;
config)
if [[ $COMP_CWORD -eq 2 ]]; then
mapfile -t COMPREPLY < <(compgen -W "www tld" -- "$cur")
elif [[ "${COMP_WORDS[2]}" == www ]]; then
mapfile -t COMPREPLY < <(compgen -d -- "$cur")
fi
;;
php)
if [[ $COMP_CWORD -eq 2 ]]; then
mapfile -t COMPREPLY < <(compgen -W "list use cli current" -- "$cur")
elif [[ "${COMP_WORDS[2]}" == use && $COMP_CWORD -eq 3 ]]; then
mapfile -t COMPREPLY < <(compgen -W "$(_nsite_sites)" -- "$cur")
elif [[ "${COMP_WORDS[2]}" == current && $COMP_CWORD -eq 3 ]]; then
mapfile -t COMPREPLY < <(compgen -W "$(_nsite_sites)" -- "$cur")
else
mapfile -t COMPREPLY < <(compgen -W "$(_nsite_php_versions)" -- "$cur")
fi
;;
esac
}
complete -F _nsite nsite