From dba106349deb4dbeac36b7acee915e6366502240 Mon Sep 17 00:00:00 2001 From: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com> Date: Sun, 4 Oct 2026 12:11:21 +0530 Subject: [PATCH 1/3] feat: add shell completions for bash, zsh and fish Static completion scripts under completions/ complete the flag names; -timeout also suggests 30s, 2m and 5m. Everything after the flags is the request, so no argument completion is offered there. The scripts are wired into the release archives (they land in completions/ inside the tarball; verified with make snapshot), the README gains a Shell completions section with per-shell install steps, and the CHANGELOG records the addition under Unreleased. --- .goreleaser.yaml | 2 ++ CHANGELOG.md | 6 ++++++ README.md | 31 +++++++++++++++++++++++++++++++ completions/_aiterm | 16 ++++++++++++++++ completions/aiterm.bash | 35 +++++++++++++++++++++++++++++++++++ completions/aiterm.fish | 12 ++++++++++++ 6 files changed, 102 insertions(+) create mode 100644 completions/_aiterm create mode 100644 completions/aiterm.bash create mode 100644 completions/aiterm.fish diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3808569..49d0ada 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -38,6 +38,8 @@ archives: - LICENSE - README.md - CHANGELOG.md + - src: completions/* + dst: completions checksum: name_template: checksums.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aa57b2..34928a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Shell completions for bash, zsh and fish in `completions/`, shipped in + the release archives. See the README's Shell completions section for + how to enable them. + ## [0.2.0] - 2026-10-04 ### Added diff --git a/README.md b/README.md index a2161b9..1bcb91d 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,37 @@ cd aiterm go build -o aiterm . ``` +## Shell completions + +Completion scripts for bash, zsh and fish live in `completions/` and are +included in the release archives. They complete the flag names; `-timeout` +also suggests a few durations. Everything after the flags is the request, +so there is nothing to complete there. + +For bash, copy the script into your completion directory and start a new +shell: + +```bash +sudo cp completions/aiterm.bash /etc/bash_completion.d/aiterm +``` + +On macOS with Homebrew the directory is `/usr/local/etc/bash_completion.d/` +(or `/opt/homebrew/etc/bash_completion.d/` on Apple silicon). + +For zsh, copy the script as `_aiterm` into a directory on your `fpath`: + +```bash +mkdir -p ~/.zsh/completions +cp completions/_aiterm ~/.zsh/completions/ +autoload -Uz compinit && compinit +``` + +For fish, copy the script into your completions directory: + +```bash +cp completions/aiterm.fish ~/.config/fish/completions/ +``` + ## Configuration `aiterm` needs an API key. Flags go before the request and take precedence over diff --git a/completions/_aiterm b/completions/_aiterm new file mode 100644 index 0000000..94768b4 --- /dev/null +++ b/completions/_aiterm @@ -0,0 +1,16 @@ +#compdef aiterm +# +# zsh completion for aiterm +# +# Install: copy or symlink this file as _aiterm into a directory on your +# fpath, e.g. ~/.zsh/completions, and run compinit. See the README's Shell +# completions section for details. + +_arguments -s -S \ + '-key=[OpenAI API key]:API key:' \ + '-url=[chat completions endpoint of an OpenAI compatible API]:URL:' \ + '-model=[model to use]:model:' \ + '-timeout=[how long to wait for the API]:duration:(30s 2m 5m)' \ + '-version[print version information and exit]' \ + '-h[show help information]' \ + '*:request:' diff --git a/completions/aiterm.bash b/completions/aiterm.bash new file mode 100644 index 0000000..90071c6 --- /dev/null +++ b/completions/aiterm.bash @@ -0,0 +1,35 @@ +# bash completion for aiterm +# +# Install: copy or symlink this file into your bash completion directory, +# e.g. /etc/bash_completion.d/ or /usr/local/etc/bash_completion.d/ on macOS +# with Homebrew, and start a new shell. See the README's Shell completions +# section for details. + +_aiterm() +{ + local cur prev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + case "$prev" in + -timeout) + COMPREPLY=( $(compgen -W "30s 2m 5m" -- "$cur") ) + return 0 + ;; + -key|-url|-model) + # Free-text values; nothing to complete. + return 0 + ;; + esac + + # Flags go before the request. Once the request has started there is + # nothing to complete: it is free text. + if [[ "$cur" == -* ]]; then + COMPREPLY=( $(compgen -W "-key -url -model -timeout -version -h -help" -- "$cur") ) + return 0 + fi + return 0 +} + +complete -F _aiterm aiterm diff --git a/completions/aiterm.fish b/completions/aiterm.fish new file mode 100644 index 0000000..8083405 --- /dev/null +++ b/completions/aiterm.fish @@ -0,0 +1,12 @@ +# fish completion for aiterm +# +# Install: copy or symlink this file into ~/.config/fish/completions/. +# See the README's Shell completions section for details. + +complete -c aiterm -o key -d 'OpenAI API key' -x +complete -c aiterm -o url -d 'chat completions endpoint of an OpenAI compatible API' -x +complete -c aiterm -o model -d 'model to use' -x +complete -c aiterm -o timeout -d 'how long to wait for the API' -x -a '30s 2m 5m' +complete -c aiterm -o version -d 'print version information and exit' +complete -c aiterm -o h -d 'show help information' +complete -c aiterm -o help -d 'show help information' From 5554a392ec449c2e46783de9a0b7137498ca7290 Mon Sep 17 00:00:00 2001 From: Thakay <43750310+Thakay@users.noreply.github.com> Date: Sun, 4 Oct 2026 16:04:37 -0700 Subject: [PATCH 2/3] fix(completions): stop offering flags once the request has started aiterm rejects a flag typed after the request, but bash and zsh still offered the flags there. bash now skips flag values (including the "-flag=value" form) and stops at the first request word or "--". zsh uses _arguments -A for the same effect, drops -s (Go flags do not stack) and completes -help like the other shells. Co-authored-by: Claude --- completions/_aiterm | 4 +++- completions/aiterm.bash | 29 +++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/completions/_aiterm b/completions/_aiterm index 94768b4..a54445b 100644 --- a/completions/_aiterm +++ b/completions/_aiterm @@ -6,11 +6,13 @@ # fpath, e.g. ~/.zsh/completions, and run compinit. See the README's Shell # completions section for details. -_arguments -s -S \ +# Flags go before the request, so -A stops offering them once it has started. +_arguments -S -A '-*' \ '-key=[OpenAI API key]:API key:' \ '-url=[chat completions endpoint of an OpenAI compatible API]:URL:' \ '-model=[model to use]:model:' \ '-timeout=[how long to wait for the API]:duration:(30s 2m 5m)' \ '-version[print version information and exit]' \ '-h[show help information]' \ + '-help[show help information]' \ '*:request:' diff --git a/completions/aiterm.bash b/completions/aiterm.bash index 90071c6..a5b9620 100644 --- a/completions/aiterm.bash +++ b/completions/aiterm.bash @@ -7,7 +7,7 @@ _aiterm() { - local cur prev + local cur prev i COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" @@ -23,11 +23,32 @@ _aiterm() ;; esac - # Flags go before the request. Once the request has started there is - # nothing to complete: it is free text. + # Flags go before the request. Once the request has started, or after + # "--", there is nothing to complete: it is free text. + for (( i = 1; i < COMP_CWORD; i++ )); do + case "${COMP_WORDS[i]}" in + --) + return 0 + ;; + -key|-url|-model|-timeout) + # Skip the value. bash splits "-flag=value" into "-flag", "=" + # and "value". + if [[ "${COMP_WORDS[i+1]}" == "=" ]]; then + (( i += 2 )) + else + (( i++ )) + fi + ;; + -*) + ;; + *) + return 0 + ;; + esac + done + if [[ "$cur" == -* ]]; then COMPREPLY=( $(compgen -W "-key -url -model -timeout -version -h -help" -- "$cur") ) - return 0 fi return 0 } From 0e369181059f880c23eeefe8e753d088484ef5aa Mon Sep 17 00:00:00 2001 From: Thakay <43750310+Thakay@users.noreply.github.com> Date: Sun, 4 Oct 2026 16:04:37 -0700 Subject: [PATCH 3/3] docs: link the man page from usage and drop the done roadmap item The usage link to the man page was suggested in #12. Co-authored-by: Claude --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7f5c43..f62ec07 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,8 @@ export AITERM_TIMEOUT="5m" # optional: give slow local models more time ## Usage +The full command reference is in the [`aiterm(1)` manual page](docs/aiterm.1). + Pass your request as arguments. Quotes are optional for plain words, but your shell expands the arguments before `aiterm` sees them, so quote the request if it contains characters such as `*`, `?`, `&`, `|`, `;`, `<`, `>`, `#`, `$` or an apostrophe. @@ -186,7 +188,6 @@ CodeQL, govulncheck and a GoReleaser snapshot build. Releases are built by ## Roadmap -- Shell completions for bash, zsh and fish ([#3](https://github.com/Thakay/aiterm/issues/3)) - An explain option that describes what a command does before you run it ([#5](https://github.com/Thakay/aiterm/issues/5)) - Anthropic and Gemini models ([#6](https://github.com/Thakay/aiterm/issues/6)) - Windows support with PowerShell commands ([#7](https://github.com/Thakay/aiterm/issues/7))