-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeng-completion.bash
More file actions
61 lines (54 loc) · 1.86 KB
/
Copy pathmeng-completion.bash
File metadata and controls
61 lines (54 loc) · 1.86 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
56
57
58
59
60
61
_meng_completions() {
local cur prev words cword
_init_completion || return
local config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/meng"
local -a aliases=() scripts=()
local line
if [[ -f "$config_dir/aliases" ]]; then
while IFS= read -r line; do
[[ -z "$line" || "$line" == \#* ]] && continue
aliases+=("${line%%=*}")
done < "$config_dir/aliases"
fi
if [[ -f "$config_dir/scripts" ]]; then
while IFS= read -r line; do
[[ -z "$line" || "$line" == \#* ]] && continue
scripts+=("${line%%=*}")
done < "$config_dir/scripts"
fi
local all_commands="ssh scp deploy info run script add remove ingest list help version"
local cmd="${words[1]}"
if [[ $cword -eq 1 ]]; then
COMPREPLY=($(compgen -W "$all_commands" -- "$cur"))
return
fi
case "$cmd" in
ssh|info|remove)
[[ $cword -eq 2 ]] && COMPREPLY=($(compgen -W "${aliases[*]}" -- "$cur"))
;;
add)
case $cword in
3) COMPREPLY=($(compgen -W "-p" -- "$cur")) ;;
esac
;;
scp|deploy)
case $cword in
2) COMPREPLY=($(compgen -W "${aliases[*]}" -- "$cur")) ;;
3) _filedir ;;
*) COMPREPLY=($(compgen -W "-r -p" -- "$cur")) ;;
esac
;;
run)
[[ $cword -eq 2 ]] && COMPREPLY=($(compgen -W "${scripts[*]}" -- "$cur"))
;;
script)
case $cword in
2) COMPREPLY=($(compgen -W "add remove" -- "$cur")) ;;
3) [[ "${words[2]}" == "remove" ]] && \
COMPREPLY=($(compgen -W "${scripts[*]}" -- "$cur")) ;;
4) [[ "${words[2]}" == "add" ]] && _filedir ;;
esac
;;
esac
}
complete -F _meng_completions meng