-
-
Save gema-arta/e8421d5dc173b4461a356175bd0e00db to your computer and use it in GitHub Desktop.
tailscale completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# tailscale completion -*- shell-script -*- | |
_tailscale() | |
{ | |
local cur prev words cword | |
_init_completion -n = || return | |
if [[ $cword -eq 1 ]]; then | |
SUBCOMMANDS=$(tailscale --help 2>&1 | awk '/SUBCOMMANDS/{ f = 1; next } /FLAGS/{ f = 0 } f{print $1}') | |
FLAGS="-h --help --socket" | |
COMPREPLY=( $(compgen -W "$SUBCOMMANDS $FLAGS" -- "$cur" )) | |
return | |
else | |
subcmd="${COMP_WORDS[1]}" | |
if [[ "$cur" = *=* ]]; then | |
COMPREPLY=( $(compgen -W 'false' -- "${cur#*=}") ) | |
return | |
elif [[ "$cur" = -* ]]; then | |
FLAGS=$(tailscale "$subcmd" --help 2>&1 | awk '/FLAGS/{ f = 1; next } f' | grep -oE -- '--[^ ]+[=]?' | tr -d ',') | |
FLAGS="$FLAGS --help" | |
COMPREPLY=( $(compgen -W "$FLAGS" -- "$cur" )) | |
return | |
else | |
case "$subcmd" in | |
"ping") | |
IP_AND_HOSTNAME=$(tailscale status 2>&1 | awk '{print $1"\n"$2}') | |
COMPREPLY=( $(compgen -W "$IP_AND_HOSTNAME" -- "$cur" )) | |
;; | |
esac | |
fi | |
fi | |
} | |
(complete -p | grep -q tailscale) || \ | |
complete -F _tailscale tailscale |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment