From c0ed6678464db62775e4b352c1031d8cdd5b9920 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 17 Feb 2026 19:38:24 +0000 Subject: [PATCH 1/2] Add shell completions for bash, zsh, and fish --- .goreleaser.yml | 12 ++++++++++++ completions/echo-http.bash | 8 ++++++++ completions/echo-http.fish | 2 ++ completions/echo-http.zsh | 15 +++++++++++++++ main.go | 4 +++- 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 completions/echo-http.bash create mode 100644 completions/echo-http.fish create mode 100644 completions/echo-http.zsh diff --git a/.goreleaser.yml b/.goreleaser.yml index 9978a9a..6c84ea1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -41,6 +41,7 @@ archives: files: - LICENSE - README.md + - completions/* rlcp: true @@ -59,6 +60,10 @@ brews: homepage: "https://echo.umputun.com" description: "Responds with json-formatted echo of the incoming request and with a predefined message." license: "MIT" + extra_install: | + bash_completion.install "completions/echo-http.bash" => "echo-http" + zsh_completion.install "completions/echo-http.zsh" => "_echo-http" + fish_completion.install "completions/echo-http.fish" => "echo-http.fish" nfpms: - id: echo-http @@ -76,3 +81,10 @@ nfpms: bindir: /usr/bin epoch: 1 release: 1 + contents: + - src: completions/echo-http.bash + dst: /usr/share/bash-completion/completions/echo-http + - src: completions/echo-http.zsh + dst: /usr/share/zsh/vendor-completions/_echo-http + - src: completions/echo-http.fish + dst: /usr/share/fish/vendor_completions.d/echo-http.fish diff --git a/completions/echo-http.bash b/completions/echo-http.bash new file mode 100644 index 0000000..80ff068 --- /dev/null +++ b/completions/echo-http.bash @@ -0,0 +1,8 @@ +# bash completion for echo-http (generated via go-flags) +_echo_http() { + local args=("${COMP_WORDS[@]:1:$COMP_CWORD}") + local IFS=$'\n' + COMPREPLY=($(GO_FLAGS_COMPLETION=1 "${COMP_WORDS[0]}" "${args[@]}" 2>/dev/null)) + return 0 +} +complete -o default -F _echo_http echo-http diff --git a/completions/echo-http.fish b/completions/echo-http.fish new file mode 100644 index 0000000..36434af --- /dev/null +++ b/completions/echo-http.fish @@ -0,0 +1,2 @@ +# fish completion for echo-http (generated via go-flags) +complete -c echo-http -a '(GO_FLAGS_COMPLETION=1 echo-http (commandline -cop) 2>/dev/null)' diff --git a/completions/echo-http.zsh b/completions/echo-http.zsh new file mode 100644 index 0000000..5fd4822 --- /dev/null +++ b/completions/echo-http.zsh @@ -0,0 +1,15 @@ +#compdef echo-http + +# zsh completion for echo-http (generated via go-flags) +_echo_http() { + local IFS=$'\n' + local -a completions + completions=($(GO_FLAGS_COMPLETION=1 "${words[1]}" "${(@)words[2,$CURRENT]}" 2>/dev/null)) + if (( ${#completions} )); then + compadd -- "${completions[@]}" + else + _files + fi +} + +_echo_http "$@" diff --git a/main.go b/main.go index fc421ba..c7b2c43 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,9 @@ var opts struct { var revision = "local" func main() { - fmt.Printf("echo-http %s\n", revision) + if os.Getenv("GO_FLAGS_COMPLETION") == "" { + fmt.Printf("echo-http %s\n", revision) + } p := flags.NewParser(&opts, flags.PrintErrors|flags.PassDoubleDash|flags.HelpFlag) p.SubcommandsOptional = true From 93309f0df540938703d7f71fb6f3c3182c86e171 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 17 Feb 2026 20:10:35 +0000 Subject: [PATCH 2/2] use verbose completions for zsh and fish descriptions --- completions/echo-http.bash | 3 +-- completions/echo-http.fish | 2 +- completions/echo-http.zsh | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/completions/echo-http.bash b/completions/echo-http.bash index 80ff068..0576f6b 100644 --- a/completions/echo-http.bash +++ b/completions/echo-http.bash @@ -1,8 +1,7 @@ # bash completion for echo-http (generated via go-flags) _echo_http() { local args=("${COMP_WORDS[@]:1:$COMP_CWORD}") - local IFS=$'\n' - COMPREPLY=($(GO_FLAGS_COMPLETION=1 "${COMP_WORDS[0]}" "${args[@]}" 2>/dev/null)) + mapfile -t COMPREPLY < <(GO_FLAGS_COMPLETION=1 "${COMP_WORDS[0]}" "${args[@]}" 2>/dev/null) return 0 } complete -o default -F _echo_http echo-http diff --git a/completions/echo-http.fish b/completions/echo-http.fish index 36434af..a7c0a2a 100644 --- a/completions/echo-http.fish +++ b/completions/echo-http.fish @@ -1,2 +1,2 @@ # fish completion for echo-http (generated via go-flags) -complete -c echo-http -a '(GO_FLAGS_COMPLETION=1 echo-http (commandline -cop) 2>/dev/null)' +complete -c echo-http -a '(GO_FLAGS_COMPLETION=verbose echo-http (commandline -cop) 2>/dev/null | string replace -r "\\s+# " "\t")' diff --git a/completions/echo-http.zsh b/completions/echo-http.zsh index 5fd4822..c1a8ab2 100644 --- a/completions/echo-http.zsh +++ b/completions/echo-http.zsh @@ -2,11 +2,24 @@ # zsh completion for echo-http (generated via go-flags) _echo_http() { - local IFS=$'\n' - local -a completions - completions=($(GO_FLAGS_COMPLETION=1 "${words[1]}" "${(@)words[2,$CURRENT]}" 2>/dev/null)) - if (( ${#completions} )); then - compadd -- "${completions[@]}" + local -a lines + lines=(${(f)"$(GO_FLAGS_COMPLETION=verbose "${words[1]}" "${(@)words[2,$CURRENT]}" 2>/dev/null)"}) + if (( ${#lines} )); then + local -a descr + local line item desc + for line in "${lines[@]}"; do + if [[ "$line" = *' # '* ]]; then + item="${line%% *}" + desc="${line#* \# }" + descr+=("${item//:/\\:}:${desc}") + else + item="${line%% *}" + [[ -z "$item" ]] && item="$line" + [[ "$item" = *" "* ]] && continue + descr+=("${item//:/\\:}") + fi + done + _describe 'command' descr else _files fi