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