From 7ecb57a8fdf1b86726609249edebad1c0ca6e6ee Mon Sep 17 00:00:00 2001 From: abs3nt Date: Sun, 18 Feb 2024 10:10:42 -0800 Subject: [PATCH] build --- Makefile | 9 +++--- completions/{zsh_autocomplete => _gospt-ng} | 0 completions/gospt-ng | 35 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) rename completions/{zsh_autocomplete => _gospt-ng} (100%) create mode 100755 completions/gospt-ng diff --git a/Makefile b/Makefile index 8850363..4f259e5 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,14 @@ tidy: go mod tidy clean: - rm -f gospt-ng - rm -rf completions + rm -rf bin uninstall: rm -f /usr/bin/gospt-ng rm -f /usr/share/zsh/site-functions/_gospt-ng rm -f /usr/share/bash-completion/completions/gospt-ng - rm -f /usr/share/fish/vendor_completions.d/gospt-ng.fish install: - cp gospt-ng /usr/bin - cp ./completions/zsh_autocomplete /usr/share/zsh/site-functions/_gospt-ng + cp ./dist/gospt-ng /usr/bin + cp ./completions/_gospt-ng /usr/share/zsh/site-functions/_gospt-ng + cp ./completions/gospt-ng /usr/share/bash-completion/completions/gospt-ng diff --git a/completions/zsh_autocomplete b/completions/_gospt-ng similarity index 100% rename from completions/zsh_autocomplete rename to completions/_gospt-ng diff --git a/completions/gospt-ng b/completions/gospt-ng new file mode 100755 index 0000000..7120a0d --- /dev/null +++ b/completions/gospt-ng @@ -0,0 +1,35 @@ +#! /bin/bash + +: ${PROG:=$(basename ${BASH_SOURCE})} + +# Macs have bash3 for which the bash-completion package doesn't include +# _init_completion. This is a minimal version of that function. +_cli_init_completion() { + COMPREPLY=() + _get_comp_words_by_ref "$@" cur prev words cword +} + +_cli_bash_autocomplete() { + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur opts base words + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if declare -F _init_completion >/dev/null 2>&1; then + _init_completion -n "=:" || return + else + _cli_init_completion -n "=:" || return + fi + words=("${words[@]:0:$cword}") + if [[ "$cur" == "-"* ]]; then + requestComp="${words[*]} ${cur} --generate-shell-completion" + else + requestComp="${words[*]} --generate-shell-completion" + fi + opts=$(eval "${requestComp}" 2>/dev/null) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + fi +} + +complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG +unset PROG