forked from Ara4Sh/sshconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssc_autocomplete
41 lines (35 loc) · 852 Bytes
/
ssc_autocomplete
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
# ssc completion -*- shell-script -*-
_ssc()
{
local cur words
_init_completion || return
local COMMANDS=(
"add"
"edit"
"help"
"iterm"
"list"
"remove"
"search"
"version"
)
local command i
for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
command=${words[i]}
break
fi
done
case $prev in
edit|remove)
host_list=$(grep -oP 'Host\s+\K\S+' $HOME/.ssh/config)
COMPREPLY=( $( compgen -W "$host_list" -- "$cur" ) )
return 0
;;
esac
if [ "$command" = "" ]; then
COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
fi
return 0
} &&
complete -F _ssc ssc