From 0adcff25a65984751bb5ddae46d300a67fe84e08 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Thu, 8 Jan 2026 16:44:12 -0500 Subject: [PATCH] better --- completions/bash/git-remote-gcrypt | 43 +++++++++++++------------ completions/fish/git-remote-gcrypt.fish | 1 + completions/zsh/_git-remote-gcrypt | 2 +- git-remote-gcrypt | 5 ++- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/completions/bash/git-remote-gcrypt b/completions/bash/git-remote-gcrypt index 93bcd15..4e46442 100644 --- a/completions/bash/git-remote-gcrypt +++ b/completions/bash/git-remote-gcrypt @@ -9,36 +9,37 @@ _git_remote_gcrypt() { opts="-h --help -v --version --check" commands="capabilities check clean fetch list push" - # If we're after a subcommand, only offer -h/--help - if [[ " $commands " =~ " ${COMP_WORDS[1]:-} " ]]; then - COMPREPLY=($(compgen -W "-h --help" -- "$cur")) + # 1. First argument: complete commands and global options + if [[ $COMP_CWORD -eq 1 ]]; then + COMPREPLY=($(compgen -W "$commands $opts" -- "$cur")) + if [[ "$cur" == gcrypt::* ]]; then + COMPREPLY+=("$cur") + fi return 0 fi - case "$prev" in - clean) - COMPREPLY=($(compgen -W "-f --force" -- "$cur")) - return 0 - ;; - --check | check) - # Complete with gcrypt:: URLs or file paths - COMPREPLY=($(compgen -f -- "$cur")) - return 0 - ;; + # 2. Handle subcommands + case "${COMP_WORDS[1]}" in + clean) + local remotes=$(git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print $1}' | sort -u || :) + COMPREPLY=($(compgen -W "-f --force -h --help $remotes" -- "$cur")) + return 0 + ;; + check|--check) + COMPREPLY=($(compgen -f -- "$cur")) + return 0 + ;; + capabilities|fetch|list|push) + COMPREPLY=($(compgen -W "-h --help" -- "$cur")) + return 0 + ;; esac + # 3. Fallback (global flags if not in a known subcommand?) if [[ "$cur" == -* ]]; then COMPREPLY=($(compgen -W "$opts" -- "$cur")) return 0 fi - - # Complete with both git protocol commands and flags on first argument - COMPREPLY=($(compgen -W "$commands $opts" -- "$cur")) - - # Also complete with gcrypt:: URLs - if [[ "$cur" == gcrypt::* ]]; then - COMPREPLY+=("$cur") - fi } complete -F _git_remote_gcrypt git-remote-gcrypt diff --git a/completions/fish/git-remote-gcrypt.fish b/completions/fish/git-remote-gcrypt.fish index 613c89c..c8f4636 100644 --- a/completions/fish/git-remote-gcrypt.fish +++ b/completions/fish/git-remote-gcrypt.fish @@ -8,6 +8,7 @@ complete -c git-remote-gcrypt -l check -d '(Legacy) Check if URL is a gcrypt rep # Subcommands complete -c git-remote-gcrypt -f -n "not __fish_seen_subcommand_from capabilities check clean fetch list push" -a 'check' -d 'Check if URL is a gcrypt repository' complete -c git-remote-gcrypt -f -n "not __fish_seen_subcommand_from capabilities check clean fetch list push" -a 'clean' -d 'Scan/Clean unencrypted files from remote' +complete -c git-remote-gcrypt -n "__fish_seen_subcommand_from clean check" -a "(git remote -v 2>/dev/null | grep 'gcrypt::' | awk '{print \$1}' | sort -u)" -d 'Gcrypt Remote' # Clean flags complete -c git-remote-gcrypt -f -n "__fish_seen_subcommand_from capabilities check clean fetch list push" -s f -l force -d 'Actually delete files during clean' diff --git a/completions/zsh/_git-remote-gcrypt b/completions/zsh/_git-remote-gcrypt index d8001b1..0fe728b 100644 --- a/completions/zsh/_git-remote-gcrypt +++ b/completions/zsh/_git-remote-gcrypt @@ -17,7 +17,7 @@ _git_remote_gcrypt() { clean) _arguments \ '(-f --force)'{-f,--force}'[actually delete files]' \ - '*:gcrypt URL:' + '*:gcrypt URL: _alternative "remotes:gcrypt remote:($(git remote -v 2>/dev/null | grep "gcrypt::" | awk "{print \$1}" | sort -u))" "files:file:_files"' ;; check) _arguments \ diff --git a/git-remote-gcrypt b/git-remote-gcrypt index a71c53f..483705e 100755 --- a/git-remote-gcrypt +++ b/git-remote-gcrypt @@ -1390,10 +1390,9 @@ elif [ "$NAME" = "gcrypt-clean" ]; then xecho "$bad_files" | sed 's/^/ /' >&2 if isnull "$FORCE_CLEAN"; then - echo_info "" echo_info "NOTE: This is a scan of unencrypted files on the remote." - echo_info "To actually delete these files, use: git-remote-gcrypt clean $URL --force" - echo_info "" + echo_info "To actually delete these files, use:" + echo_info " git-remote-gcrypt clean $URL --force" CLEAN_FINAL "$URL" git remote remove "$NAME" 2>/dev/null || true exit 0 -- 2.52.0