forked from 8go/matrix-commander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix-commander.bash
105 lines (98 loc) · 2.38 KB
/
matrix-commander.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
_matrix-commander-get-last-option ()
{
local lastopt i
for (( i = ${#COMP_WORDS[@]} - 1; i >= 0; i-- )); do
if [[ "${COMP_WORDS[i]}" = -* ]]; then
lastopt="${COMP_WORDS[i]}"
break
fi
done
echo $lastopt
}
_matrix-commander ()
{
COMPREPLY=()
local IFS=$'\n'
local -a opts keys
cur=${COMP_WORDS[COMP_CWORD]}
# prev is generally not useful since nargs=+
prev=${COMP_WORDS[COMP_CWORD-1]}
opts=(
-h --help
-d --debug
--log-level
-c --credentials
-r --room
--room-create
--room-join
--room-leave
--room-forget
--room-invite
--room-ban
--room-unban
--room-kick
--user
--name
--topic
-m --message
-i --image
-a --audio
-f --file
-w --html
-z --markdown
-k --code
-p --split
-j --config
--proxy
-n --notice
-e --encrypted
-s --store
-l --listen
-t --tail
-y --listen-self
--print-event-id
-u --download-media
-o --os-notify
-v --verify
-x --rename-device
--version
)
# option
if [[ "$cur" = -* ]]; then
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
return 0
fi
# argument to option
opt=$(_matrix-commander-get-last-option)
case "$opt" in
--log-level)
keys=(DEBUG INFO WARNING ERROR CRITICAL)
COMPREPLY=( $(compgen -W "${keys[*]}" -- "$cur") )
;;
-c|--credentials)
COMPREPLY=( $(compgen -f -- "$cur") )
;;
-i|--image|-a|--audio|-f|--file)
# just allow all files since it is hard to distinguish
COMPREPLY=( $(compgen -f -- "$cur") )
;;
-s|--store)
COMPREPLY=( $(compgen -d -- "$cur") )
;;
-l|--listen)
keys=(never once forever tail all)
COMPREPLY=( $(compgen -W "${keys[*]}" -- "$cur") )
;;
-j|--config)
COMPREPLY=( $(compgen -f -- "$cur") )
;;
-v|--verify)
keys=(emoji)
COMPREPLY=( $(compgen -W "${keys[*]}" -- "$cur") )
;;
*)
return 1
;;
esac
}
complete -F _matrix-commander matrix-commander.py