From 37377882097b3860b4b9e2a5e8f1bab049d893c6 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sat, 30 Dec 2023 20:24:19 +1000 Subject: [PATCH] feat: initial plugin implementation for client binaries --- functions/.gitignore | 3 +++ init.zsh | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 functions/.gitignore create mode 100644 init.zsh diff --git a/functions/.gitignore b/functions/.gitignore new file mode 100644 index 0000000..f309f9e --- /dev/null +++ b/functions/.gitignore @@ -0,0 +1,3 @@ +_tsh +_tctl +_tbot diff --git a/init.zsh b/init.zsh new file mode 100644 index 0000000..aefdd7e --- /dev/null +++ b/init.zsh @@ -0,0 +1,21 @@ +generate_completions() { + if [[ ${+commands[(e)${2}]} || ${+commands[asdf]} && ${+functions[_direnv_hook]} ]]; then + + local command=${commands[(e)${2}]:-"$(${commands[asdf]} which $2 2> /dev/null)"} + + [[ -z $command ]] && return 1 + + local compfile=$1/functions/_$2 + if [[ ! -e $compfile || $compfile -ot $command ]]; then + $command --completion-script-zsh >| $compfile + print -u2 -PR "* Detected a new version '$2'. Regenerated completions." + fi + fi +} + +# Teleport user CLI +generate_completions "${0:h}" tsh +# Teleport admin CLI +generate_completions "${0:h}" tctl +# Machine ID Bot +generate_completions "${0:h}" tbot