Files
ccs/scripts/completion/ccs.zsh
T
Kai (Tam Nhu) TranandGitHub f40e9647ec feat(cli): comprehensive UX improvements for v3.5.0 (#7)
Implements 6-phase CLI UX improvement plan with comprehensive error handling, 
interactive features, and cross-platform consistency.

### Added
- Shell auto-completion (bash, zsh, PowerShell, Fish)
- Error codes (E101-E901) with documentation URLs
- Fuzzy matching "Did you mean?" suggestions (Levenshtein distance)
- Progress indicators (doctor [n/9] counter, GLMT proxy spinner)
- Interactive confirmation prompts with --yes/-y automation flag
- JSON output format (--json) for auth commands
- Impact display (session count, paths) before destructive operations
- Comprehensive test suite (15 tests, 100% pass rate)
- Complete error documentation in docs/errors/
- Cross-platform `--shell-completion` command

### Changed
- Error boxes: Unicode (╔═╗) → ASCII (===) for compatibility
- JSON output uses CCS version instead of schema version
- Help text includes EXAMPLES section across platforms
- Test suite properly counts test cases (not assertions)

### Fixed
- --yes flag bug (returned false instead of true)
- Help text consistency (added Uninstall section to bash)
- Test pass rate calculation (excludes skipped tests)
- Help section comparison (locale-specific sort)

### Testing
- 13/13 tests passing (2 legitimately skipped)
- Cross-platform verified (Node.js, bash, PowerShell)
- All error codes documented and tested
2025-11-15 01:26:50 -05:00

131 lines
3.2 KiB
Bash

#compdef ccs
# Zsh completion for CCS (Claude Code Switch)
# Compatible with zsh 5.0+
#
# Installation:
# Add to ~/.zshrc:
# fpath=(~/.zsh/completion $fpath)
# autoload -Uz compinit && compinit
# source /path/to/ccs/scripts/completion/ccs.zsh
#
# Or install system-wide:
# sudo cp scripts/completion/ccs.zsh /usr/local/share/zsh/site-functions/_ccs
_ccs() {
local -a commands profiles settings_profiles account_profiles
local curcontext="$curcontext" state line
typeset -A opt_args
# Define top-level commands
commands=(
'auth:Manage multiple Claude accounts'
'doctor:Run health check and diagnostics'
)
# Load settings-based profiles from config.json
if [[ -f ~/.ccs/config.json ]]; then
settings_profiles=(${(f)"$(jq -r '.profiles | keys[]' ~/.ccs/config.json 2>/dev/null)"})
fi
# Load account-based profiles from profiles.json
if [[ -f ~/.ccs/profiles.json ]]; then
account_profiles=(${(f)"$(jq -r '.profiles | keys[]' ~/.ccs/profiles.json 2>/dev/null)"})
fi
# Combine all profiles
profiles=($settings_profiles $account_profiles)
_arguments -C \
'(- *)'{-h,--help}'[Show help message]' \
'(- *)'{-v,--version}'[Show version information]' \
'1: :->command' \
'*:: :->args'
case $state in
command)
local -a all_options
all_options=($commands $profiles)
_describe -t commands 'ccs commands' all_options
;;
args)
case $words[1] in
auth)
_ccs_auth
;;
doctor)
_arguments \
'(- *)'{-h,--help}'[Show help for doctor command]'
;;
*)
# For profile names, complete with Claude CLI arguments
_message 'Claude CLI arguments'
;;
esac
;;
esac
}
_ccs_auth() {
local curcontext="$curcontext" state line
typeset -A opt_args
local -a auth_commands account_profiles
# Define auth subcommands
auth_commands=(
'create:Create new profile and login'
'list:List all saved profiles'
'show:Show profile details'
'remove:Remove saved profile'
'default:Set default profile'
)
# Load account profiles
if [[ -f ~/.ccs/profiles.json ]]; then
account_profiles=(${(f)"$(jq -r '.profiles | keys[]' ~/.ccs/profiles.json 2>/dev/null)"})
fi
_arguments -C \
'(- *)'{-h,--help}'[Show help for auth commands]' \
'1: :->subcommand' \
'*:: :->subargs'
case $state in
subcommand)
_describe -t auth-commands 'auth commands' auth_commands
;;
subargs)
case $words[1] in
create)
_message 'new profile name'
_arguments '--force[Allow overwriting existing profile]'
;;
list)
_arguments \
'--verbose[Show additional details]' \
'--json[Output in JSON format]'
;;
show)
_arguments \
'1:profile:($account_profiles)' \
'--json[Output in JSON format]'
;;
remove)
_arguments \
'1:profile:($account_profiles)' \
{--yes,-y}'[Skip confirmation prompts]'
;;
default)
_arguments '1:profile:($account_profiles)'
;;
esac
;;
esac
}
# Register the completion function
_ccs "$@"