Skip to content

Commit c92e030

Browse files
committed
Create a bash completion script.
Just adding it to the repo, but it still needs to be dealt with during install. Probably put it in $ZT_HOME and then symlink to the proper place for the distro? searches $ZT_HOME/networks.d/ for network IDs searches HISTORY for 16 digit numbers that look like network IDs.
1 parent ff50762 commit c92e030

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

zerotier-cli-completion.bash

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#compdef zerotier-cli
2+
#autoload
3+
4+
5+
_get_network_ids ()
6+
{
7+
if [[ "$OSTYPE" == "darwin"* ]]; then
8+
COMPREPLY=($(compgen -W "$(ls -1 /Library/Application\ Support/ZeroTier/One/networks.d | cut -c 1-16)" -- ${cur}))
9+
else
10+
COMPREPLY=($(compgen -W "$(ls -1 /var/lib/zerotier-one/networks.d | cut -c 1-16)" -- ${cur}))
11+
fi
12+
}
13+
14+
_get_network_ids_from_history ()
15+
{
16+
COMPREPLY=($(compgen -W "$(fc -l -1000 -1 | sed -n 's/.*\([[:xdigit:]]\{16\}\).*/\1/p')" -- ${cur}))
17+
}
18+
19+
_zerotier-cli_completions()
20+
{
21+
local cur prev
22+
23+
cur=${COMP_WORDS[COMP_CWORD]}
24+
prev=${COMP_WORDS[COMP_CWORD-1]}
25+
26+
case ${COMP_CWORD} in
27+
1)
28+
COMPREPLY=($(compgen -W "info listpeers peers listnetworks join leave set get listmoons orbit deorbit" -- ${cur}))
29+
;;
30+
2)
31+
case ${prev} in
32+
leave)
33+
_get_network_ids
34+
;;
35+
join)
36+
_get_network_ids_from_history
37+
;;
38+
set)
39+
_get_network_ids
40+
;;
41+
get)
42+
_get_network_ids
43+
;;
44+
*)
45+
COMPREPLY=()
46+
;;
47+
esac
48+
;;
49+
*)
50+
COMPREPLY=()
51+
;;
52+
esac
53+
}
54+
55+
complete -F _zerotier-cli_completions zerotier-cli
56+
57+

0 commit comments

Comments
 (0)