#!/usr/bin/env bash set -eo pipefail declare -r normal='\e[0m' declare -r bold='\e[1m' declare -r mute='\e[2m' declare -r italic='\e[3m' declare -r underline='\e[4m' declare -r red='\e[31m' declare -r green='\e[32m' declare -r yellow='\e[33m' declare -r blue='\e[34m' declare -r magenta='\e[35m' declare -r cyan='\e[36m' function log() { >&2 command echo "${@}" } function log.info() { log -e "${cyan}${mute}[info]${normal} ${@}" } function log.warn() { log -e "${yellow}${mute}[warn]${normal} ${@}" } function log.error() { log -e "${red}${mute}[error]${normal} ${@}" } declare -A default_completion_dir default_completion_dir[bash]="${XDG_DATA_HOME:-"${HOME}/.local/share"}/bash-completion/completions" default_completion_dir[fish]="${HOME}/.config/fish/completions" default_completion_dir[zsh]="${XDG_DATA_HOME:-"${HOME}/.local/share"}/zsh/completions" declare -A completion_generator_command_template completion_generator_command_template[alacritty:bash]="curl -fsSL https://raw.githubusercontent.com/alacritty/alacritty/master/extra/completions/{bin}.{shell}" completion_generator_command_template[alacritty]="curl -fsSL https://raw.githubusercontent.com/alacritty/alacritty/master/extra/completions/{filename}" completion_generator_command_template[apt-fast]="curl -fsSL https://raw.githubusercontent.com/ilikenwf/apt-fast/master/completions/{shell}/{filename}" completion_generator_command_template[atuin]="{bin} gen-completions --shell {shell}" completion_generator_command_template[bw]="{bin} completion --shell {shell}" completion_generator_command_template[cargo]="rustup completions {shell} {bin}" completion_generator_command_template[chezmoi]="{bin} completion {shell}" completion_generator_command_template[delta]="curl -fsSL https://raw.githubusercontent.com/dandavison/delta/master/etc/completion/completion.{shell}" completion_generator_command_template[deno]="{bin} completions {shell}" completion_generator_command_template[docker-compose]="curl -fsSL https://raw.githubusercontent.com/docker/compose/master/contrib/completion/{shell}/{filename}" completion_generator_command_template[docker]="{bin} completion {shell}" completion_generator_command_template[earthly]="{bin} bootstrap --no-buildkit --source {shell}" completion_generator_command_template[ente]="{bin} completion {shell}" completion_generator_command_template[exa]="curl -fsSL https://raw.githubusercontent.com/ogham/exa/master/completions/{shell}/{filename}" completion_generator_command_template[exercism]="curl -fsSL https://raw.githubusercontent.com/exercism/cli/main/shell/{bin}_completion.{shell}" completion_generator_command_template[exercism:fish]="curl -fsSL https://raw.githubusercontent.com/exercism/cli/main/shell/{bin}.{shell}" completion_generator_command_template[eza]="curl -fsSL https://raw.githubusercontent.com/eza-community/eza/main/completions/{shell}/{filename}" completion_generator_command_template[fnm]="{bin} completions --shell {shell}" completion_generator_command_template[gh]="{bin} completion --shell {shell}" completion_generator_command_template[gopass]="{bin} completion {shell}" completion_generator_command_template[hishtory]="{bin} completion {shell}" completion_generator_command_template[kubectl]="{bin} completion {shell}" completion_generator_command_template[lf]="curl -fsSL https://raw.githubusercontent.com/gokcehan/lf/master/etc/{bin}.{shell}" completion_generator_command_template[luver]="{bin} completion {shell}" completion_generator_command_template[nc-docker:zsh]="cat ${DOTFILES}/.scripts.sh/completions/{filename}" completion_generator_command_template[ncd:zsh]="{bin} completion {shell}" completion_generator_command_template[netlify]="{bin} completion:generate --shell {shell}" completion_generator_command_template[nvm:bash]="curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/master/{shell}_completion" completion_generator_command_template[pnpm]="{bin} completion {shell}" completion_generator_command_template[poetry]="{bin} completions {shell}" completion_generator_command_template[pyenv]="curl -fsSL https://raw.githubusercontent.com/pyenv/pyenv/master/completions/{bin}.{shell}" completion_generator_command_template[rbenv:bash]="curl -fsSL https://raw.githubusercontent.com/rbenv/rbenv/master/completions/{bin}.{shell}" completion_generator_command_template[rbenv:zsh]="curl -fsSL https://raw.githubusercontent.com/rbenv/rbenv/master/completions/{filename}" completion_generator_command_template[rustup]="{bin} completions {shell}" completion_generator_command_template[rye]="{bin} self completion -s {shell}" completion_generator_command_template[snap]="curl -fsSL https://raw.githubusercontent.com/snapcore/snapd/master/data/completion/{shell}/{filename}" completion_generator_command_template[starship]="{bin} completions {shell}" completion_generator_command_template[stripe]="{bin} completion --shell {shell} --write-to-stdout" completion_generator_command_template[volta]="{bin} completions {shell}" completion_generator_command_template[warp-cli]="{bin} generate-completions {shell}" declare -a valid_shells=("bash" "fish" "zsh") is-valid-shell() { local -r shell="${1}" printf '%s\n' "${valid_shells[@]}" | grep -q -e "^${shell}$" } declare -a valid_tools=() for tool in "${!completion_generator_command_template[@]}"; do valid_tools+=("${tool%%:*}") done valid_tools=($(printf '%s\n' "${valid_tools[@]}" | sort | uniq)) is-valid-tool() { local -r tool="${1}" printf '%s\n' "${valid_tools[@]}" | grep -q -e "^${tool}$" } declare shell="$(basename "$(echo ${SHELL})")" show-help() { log "Usage:" log " generate-completion [OPTIONS] [TOOLS..]" log log "OPTIONS" log " --all generate for all available tools" log " --dir