From 0d1f1246d59b1fe88f4d399ef423b064a384aab5 Mon Sep 17 00:00:00 2001 From: Simone Date: Tue, 9 Jun 2026 23:50:02 +0200 Subject: [PATCH] feat(cli): install `ci` shell completion via install-ci-alias.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generate a click completion file for bash/zsh and source it from the alias block. Click's generated script queries completions by invoking the command — but `ci` is a sudo shell function (env vars don't survive sudo, and `env VAR=x ci` can't call a function), so rewrite the query to call the venv python directly (read-only, no sudo) and drop zsh's `$+commands[ci]` guard. Writes ~/.ci-completion.; removed cleanly on --uninstall (block strip). --- scripts/install-ci-alias.sh | 42 ++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/scripts/install-ci-alias.sh b/scripts/install-ci-alias.sh index dd3aa13..c0d7004 100755 --- a/scripts/install-ci-alias.sh +++ b/scripts/install-ci-alias.sh @@ -24,14 +24,37 @@ log() { printf '[install-ci-alias] %s\n' "$*"; } die() { printf '[install-ci-alias] ERROR: %s\n' "$*" >&2; exit 1; } block() { + # $1 (optional): path to a shell-completion file to source from the block. + local cmpl="${1:-}" cat </dev/null \ + | sed -e "s#_CI_COMPLETE=zsh_complete ci)#_CI_COMPLETE=zsh_complete ${PROD_PY} -m ci_orchestrator)#" \ + -e '/\$+commands\[ci\]/d' > "$out" ;; + bash) + _CI_COMPLETE=bash_source "$PROD_PY" -m ci_orchestrator 2>/dev/null \ + | sed -e "s#_CI_COMPLETE=bash_complete \$1#_CI_COMPLETE=bash_complete ${PROD_PY} -m ci_orchestrator#" > "$out" ;; + *) return 1 ;; + esac + [ -s "$out" ] || { rm -f "$out"; return 1; } } strip_block() { @@ -47,9 +70,22 @@ strip_block() { } install_into() { - local file="$1" + local file="$1" shell="" cmpl="" + case "$file" in + *.zshrc) shell="zsh" ;; + *.bashrc) shell="bash" ;; + esac + if [ -n "$shell" ] && [ -x "$PROD_PY" ]; then + cmpl="$HOME/.ci-completion.$shell" + if gen_completion "$cmpl" "$shell"; then + log "wrote $shell completion: $cmpl" + else + cmpl="" + log "WARNING: could not generate $shell completion — skipped (alias still installed)." + fi + fi strip_block "$file" - { printf '\n'; block; } >> "$file" + { printf '\n'; block "$cmpl"; } >> "$file" log "updated $file" }