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
# 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'
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