Add shell auto-completion for zsh, bash, and fish

- completions/_ssr            zsh #compdef completion using _arguments/_values
- completions/ssr.bash        bash complete -F function (works with bash-completion@2)
- completions/ssr.fish        fish completions with __ssr_needs_subcmd predicates
- bin/ssr-completions         install/uninstall/status subcommand
                              - auto-detects $SHELL, --shell zsh|bash|fish|all
                              - symlinks into user-scoped paths (no sudo):
                                ~/.zsh/completions/_ssr
                                ~/.local/share/bash-completion/completions/ssr
                                ~/.config/fish/completions/ssr.fish
                              - prints fpath/bash-completion setup hints if not configured
- bin/ssr                     dispatcher knows `completions`; help line added
- bin/ssr-install             offers completion install after schedule prompt
- README                      Shell completions section, command list, layout entry

Verified:
- zsh -n  on _ssr        OK; autoload registers function
- bash -n on ssr.bash    OK; `complete -p ssr` returns the registration after source
- end-to-end install/status/uninstall against an ephemeral $HOME

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-11 16:16:22 +02:00
parent 69541209dc
commit c1848f66e8
7 changed files with 383 additions and 1 deletions
+69
View File
@@ -0,0 +1,69 @@
# bash completion for ssr — System Sync & Restore.
# Source from your ~/.bashrc or place under ~/.local/share/bash-completion/completions/ssr
_ssr() {
local cur prev words cword
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion || return
else
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
words=("${COMP_WORDS[@]}")
cword=$COMP_CWORD
fi
local commands="install sync restore update schedule config completions status version help"
local global_flags="-c --config -h --help"
# Detect command (first non-flag word after `ssr`).
local cmd=""
local i
for ((i = 1; i < cword; i++)); do
case "${words[i]}" in
-c|--config) ((i++)); continue ;;
-*) continue ;;
*) cmd="${words[i]}"; break ;;
esac
done
# Handle --config <path>.
if [[ "$prev" == "-c" || "$prev" == "--config" ]]; then
COMPREPLY=( $(compgen -f -- "$cur") )
return
fi
# Top-level command selection.
if [[ -z "$cmd" ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$global_flags" -- "$cur") )
else
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
fi
return
fi
# Per-command argument completion.
case "$cmd" in
restore)
COMPREPLY=( $(compgen -f -- "$cur") )
;;
update)
COMPREPLY=( $(compgen -W "--dry-run -n -h --help" -- "$cur") )
;;
schedule)
COMPREPLY=( $(compgen -W "on off status" -- "$cur") )
;;
config)
COMPREPLY=( $(compgen -W "show edit path" -- "$cur") )
;;
completions)
COMPREPLY=( $(compgen -W "install uninstall status" -- "$cur") )
;;
*)
COMPREPLY=()
;;
esac
}
complete -F _ssr ssr