fix: add completion for tailscale
This commit is contained in:
parent
c3094c4b76
commit
b79ef12b4e
|
@ -86,6 +86,47 @@ in {
|
|||
source ${config.age.secrets.environment-secrets.path}
|
||||
source ${flake.inputs.tritonshell.packages.${pkgs.system}.triton-utils}/bin/ttp.sh
|
||||
|
||||
_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}')
|
||||
SUBCOMMANDS="$SUBCOMMANDS debug"
|
||||
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"|"ssh")
|
||||
IP_AND_HOSTNAME=$(tailscale status 2>&1 | awk '{print $1"\n"$2}')
|
||||
COMPREPLY=( $(compgen -W "$IP_AND_HOSTNAME" -- "$cur" ))
|
||||
;;
|
||||
"debug")
|
||||
SUBCOMMANDS=""
|
||||
if [[ $cword -eq 2 ]]; then
|
||||
SUBCOMMANDS=$(tailscale "$subcmd" --help 2>&1 | awk '/SUBCOMMANDS/{ f = 1; next } /FLAGS/{ f = 0 } f{print $1}')
|
||||
fi
|
||||
FLAGS=$(tailscale "$subcmd" --help 2>&1 | awk '/FLAGS/{ f = 1; next } f' | grep -oE -- '--[^ ]+[=]?' | tr -d ',')
|
||||
COMPREPLY=( $(compgen -W "$SUBCOMMANDS $FLAGS" -- "$cur" ))
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _tailscale tailscale
|
||||
complete -C ${pkgs.consul}/bin/consul consul
|
||||
complete -C ${pkgs.nomad}/bin/nomad nomad
|
||||
complete -C ${pkgs.vault}/bin/vault vault
|
||||
|
|
Loading…
Reference in a new issue