-
Notifications
You must be signed in to change notification settings - Fork 27
feat: auto-install shell completions via install #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,8 @@ Install utility for $BIN_NAME | |
| Usage: $0 [-d install_dir] | ||
|
|
||
| Environment Variables: | ||
| GITHUB_TOKEN GitHub token to avoid API rate limits (no special scopes required) | ||
| GITHUB_TOKEN GitHub token to avoid API rate limits (no special scopes required) | ||
| AICR_NO_COMPLETIONS Set to 1 to skip shell completion installation | ||
|
|
||
| Examples: | ||
| $0 # Install to /usr/local/bin | ||
|
|
@@ -106,6 +107,96 @@ get_archive_name() { | |
| echo "${BIN_NAME}_${ver}_${2}_${3}.tar.gz" # version, os, arch | ||
| } | ||
|
|
||
| # ============================================================================== | ||
| # Shell Completion Setup | ||
| # ============================================================================== | ||
|
|
||
| write_completion() { | ||
| local bin_path="$1" shell="$2" target="$3" | ||
| local target_dir tmp_file | ||
| target_dir=$(dirname "$target") | ||
| mkdir -p "$target_dir" 2>/dev/null || sudo mkdir -p "$target_dir" 2>/dev/null || return 1 | ||
| tmp_file=$(mktemp) || return 1 | ||
| if ! "$bin_path" completion "$shell" > "$tmp_file" 2>/dev/null || [[ ! -s "$tmp_file" ]]; then | ||
| rm -f "$tmp_file" | ||
| return 1 | ||
| fi | ||
| if [[ -w "$target_dir" ]]; then | ||
| mv "$tmp_file" "$target" || { rm -f "$tmp_file"; return 1; } | ||
| else | ||
| sudo mv "$tmp_file" "$target" || { rm -f "$tmp_file"; return 1; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main thing — |
||
| fi | ||
| } | ||
|
|
||
| setup_bash_completions() { | ||
| local bin_path="$1" os="$2" xdg_data="$3" | ||
| local sys_dir | ||
| if [[ "$os" == "darwin" ]]; then | ||
| local brew_prefix="/usr/local" | ||
| [[ -d /opt/homebrew ]] && brew_prefix="/opt/homebrew" | ||
| sys_dir="${brew_prefix}/etc/bash_completion.d" | ||
| else | ||
| sys_dir="/usr/share/bash-completion/completions" | ||
| fi | ||
|
|
||
| if write_completion "$bin_path" bash "${sys_dir}/aicr"; then | ||
| ok "Bash completions installed" | ||
| elif write_completion "$bin_path" bash "${xdg_data}/bash-completion/completions/aicr"; then | ||
| ok "Bash completions installed (user-local)" | ||
| else | ||
| warn "Could not install bash completions" | ||
| fi | ||
| } | ||
|
|
||
| setup_zsh_completions() { | ||
| local bin_path="$1" os="$2" xdg_data="$3" | ||
| local sys_dir | ||
| if [[ "$os" == "darwin" ]]; then | ||
| local brew_prefix="/usr/local" | ||
| [[ -d /opt/homebrew ]] && brew_prefix="/opt/homebrew" | ||
| sys_dir="${brew_prefix}/share/zsh/site-functions" | ||
| else | ||
| sys_dir="/usr/local/share/zsh/site-functions" | ||
| fi | ||
|
|
||
| if write_completion "$bin_path" zsh "${sys_dir}/_aicr"; then | ||
| ok "Zsh completions installed" | ||
| elif write_completion "$bin_path" zsh "${xdg_data}/zsh/site-functions/_aicr"; then | ||
| ok "Zsh completions installed (user-local)" | ||
| else | ||
| warn "Could not install zsh completions" | ||
| fi | ||
| } | ||
|
|
||
| setup_fish_completions() { | ||
| local bin_path="$1" | ||
| local fish_dir="${XDG_CONFIG_HOME:-$HOME/.config}/fish" | ||
| [[ -d "$fish_dir" ]] || return 0 | ||
|
||
|
|
||
| if write_completion "$bin_path" fish "${fish_dir}/completions/aicr.fish"; then | ||
| ok "Fish completions installed" | ||
| else | ||
| warn "Could not install fish completions" | ||
| fi | ||
| } | ||
|
|
||
| setup_completions() { | ||
| if [[ "${AICR_NO_COMPLETIONS:-0}" == "1" ]]; then | ||
| info "Skipping shell completion setup (AICR_NO_COMPLETIONS=1)" | ||
| return 0 | ||
| fi | ||
|
|
||
| local bin_path="${INSTALL_DIR}/${BIN_NAME}" | ||
| local os xdg_data | ||
| os=$(get_os) | ||
| xdg_data="${XDG_DATA_HOME:-$HOME/.local/share}" | ||
| step "Setting up shell completions..." | ||
|
|
||
| setup_bash_completions "$bin_path" "$os" "$xdg_data" | ||
| setup_zsh_completions "$bin_path" "$os" "$xdg_data" | ||
| setup_fish_completions "$bin_path" | ||
| } | ||
|
|
||
| # ============================================================================== | ||
| # GitHub API Functions | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Minor — confirmed by all 3 reviewers] Iterative cross-review: Claude Code AGREE, Codex AGREE, CodeRabbit AGREE
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| # ============================================================================== | ||
|
|
@@ -313,6 +404,9 @@ main() { | |
| [[ -f "${INSTALL_DIR}/${BIN_NAME}-attestation.sigstore.json" ]] && \ | ||
| msg "Attestation: ${INSTALL_DIR}/${BIN_NAME}-attestation.sigstore.json" | ||
|
|
||
| # Install shell completions | ||
| setup_completions || true | ||
|
|
||
| # Fetch latest Sigstore trusted root for offline verification. | ||
| # The trusted root enables 'aicr verify' to check attestation signatures | ||
| # without contacting Sigstore infrastructure. If this fails (e.g., no network), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Major — confirmed by all 3 reviewers]
mktempcreates files with 0600 permissions. Aftersudo mvto a system completion dir, non-root users can't read the file — completions silently fail. Addchmod 644 "$tmp_file"before themv.Iterative cross-review: Claude Code AGREE, Codex AGREE, CodeRabbit AGREE