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:
@@ -0,0 +1,67 @@
|
||||
#compdef ssr
|
||||
# zsh completion for ssr — System Sync & Restore.
|
||||
# Install: copy or symlink into a directory on $fpath, then `autoload -Uz _ssr`.
|
||||
|
||||
_ssr() {
|
||||
local context state line
|
||||
typeset -A opt_args
|
||||
|
||||
local -a commands=(
|
||||
'install:First-time install (link binary, seed config, schedule sync)'
|
||||
'sync:Run a backup → cloud'
|
||||
'restore:Restore a machine (defaults to cloud Brewfile)'
|
||||
'update:Pull latest ssr code, refresh launchd if needed'
|
||||
'schedule:Manage the scheduled launchd sync job'
|
||||
'config:Show or edit the active config file'
|
||||
'completions:Install or remove shell completions'
|
||||
'status:Show last sync time, cloud target, schedule state'
|
||||
'version:Print version'
|
||||
'help:Show top-level help'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
'(-h --help)'{-h,--help}'[Show help]' \
|
||||
'(-c --config)'{-c,--config}'[Use a specific config file]:path:_files' \
|
||||
'1: :->cmd' \
|
||||
'*::arg:->args'
|
||||
|
||||
case "$state" in
|
||||
cmd)
|
||||
_describe -t commands 'ssr command' commands
|
||||
;;
|
||||
args)
|
||||
case "${line[1]}" in
|
||||
restore)
|
||||
_arguments \
|
||||
'(-h --help)'{-h,--help}'[Show help]' \
|
||||
'1:Brewfile:_files'
|
||||
;;
|
||||
update)
|
||||
_arguments \
|
||||
'(-h --help)'{-h,--help}'[Show help]' \
|
||||
'(-n --dry-run)'{-n,--dry-run}'[Preview without pulling]'
|
||||
;;
|
||||
schedule)
|
||||
_values 'schedule action' \
|
||||
'on[Enable scheduled sync]' \
|
||||
'off[Disable scheduled sync]' \
|
||||
'status[Show schedule state]'
|
||||
;;
|
||||
config)
|
||||
_values 'config action' \
|
||||
'show[Print active config]' \
|
||||
'edit[Open config in $EDITOR]' \
|
||||
'path[Print config path]'
|
||||
;;
|
||||
completions)
|
||||
_values 'completions action' \
|
||||
'install[Install shell completions]' \
|
||||
'uninstall[Remove shell completions]' \
|
||||
'status[Show installed completions]'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_ssr "$@"
|
||||
Reference in New Issue
Block a user