#compdef muse # _muse — ZSH completion for the muse CLI # ============================================================================== # Relies on MUSE_REPO_ROOT exported by muse.plugin.zsh. All file reads are # pure ZSH globbing — no subprocesses, no ls, no eval. # ============================================================================== # List branch names from .muse/refs/heads/ using ZSH globbing (no subprocess). function _muse_branches() { local refs_dir="${MUSE_REPO_ROOT}/.muse/refs/heads" [[ -d "$refs_dir" ]] || return local -a branches branches=("${refs_dir}"/*(N:t)) # (N) = nullglob, :t = tail (basename) (( ${#branches} )) && _describe 'branch' branches } # List tag names from .muse/refs/tags/. function _muse_tags() { local tags_dir="${MUSE_REPO_ROOT}/.muse/refs/tags" [[ -d "$tags_dir" ]] || return local -a tags tags=("${tags_dir}"/*(N:t)) (( ${#tags} )) && _describe 'tag' tags } # List remote names from .muse/remotes/. function _muse_remotes() { local remotes_dir="${MUSE_REPO_ROOT}/.muse/remotes" [[ -d "$remotes_dir" ]] || return local -a remotes remotes=("${remotes_dir}"/*(N:t)) (( ${#remotes} )) && _describe 'remote' remotes } # Main completion function. function _muse() { local state line typeset -A opt_args _arguments -C \ '(-h --help)'{-h,--help}'[show help]' \ '(-V --version)'{-V,--version}'[show version]' \ '1: :->command' \ '*:: :->args' case "$state" in command) local -a cmds cmds=( 'init:initialise a new muse repository' 'status:show working-tree status' 'log:show commit history' 'diff:show changes between commits or working tree' 'show:show a commit or object' 'commit:record changes to the repository' 'branch:list, create, or delete branches' 'checkout:switch branches or restore files' 'merge:join two branches' 'reset:reset HEAD to a given state' 'revert:create a new commit that undoes a prior commit' 'cherry-pick:apply a commit onto the current branch' 'stash:stash uncommitted changes' 'tag:create, list, or delete tags' 'blame:annotate lines with commit info' 'reflog:show reference log' 'gc:run repository maintenance' 'remote:manage remote repositories' 'fetch:download objects and refs from a remote' 'pull:fetch and integrate from a remote' 'push:update remote refs and send objects' 'clone:clone a repository' 'config:read or write repository config' 'domains:list registered domain plugins' 'workspace:manage multi-domain workspaces' 'worktree:manage linked working trees' 'archive:create an archive of repository contents' 'annotate:add structured annotations to commits' 'attributes:manage path attribute rules' 'check:run repository integrity checks' 'hub:interact with Muse Hub repositories' 'auth:manage authentication credentials' 'midi:MIDI domain subcommands' 'code:code domain subcommands' 'plumbing:low-level plumbing commands' ) _describe 'muse command' cmds ;; args) case "${line[1]}" in checkout|merge|cherry-pick|branch|revert|reset) _muse_branches ;; push|pull|fetch) local -a remote_args remote_args=() _muse_remotes ;; tag) case "${line[2]}" in -d|--delete) _muse_tags ;; *) _muse_tags ;; esac ;; blame|show|diff) _muse_branches ;; config) if (( ${#line} == 2 )); then local -a keys keys=( 'core.domain:active domain plugin' 'core.user:commit author name' 'core.email:commit author email' 'core.editor:preferred editor' 'core.pager:preferred pager' 'core.autocrlf:line-ending conversion' 'core.filemode:track execute permission' 'push.default:default push behaviour' 'merge.conflictstyle:conflict marker style' 'log.oneline:default log format' ) _describe 'config key' keys fi ;; stash) local -a stash_cmds stash_cmds=( 'push:stash the working tree' 'pop:apply and drop the latest stash' 'apply:apply a stash without dropping it' 'list:list stash entries' 'drop:discard a stash entry' 'show:inspect a stash entry' ) _describe 'stash subcommand' stash_cmds ;; remote) local -a remote_cmds remote_cmds=( 'add:add a remote' 'remove:remove a remote' 'rename:rename a remote' 'list:list configured remotes' 'show:show remote info' 'set-url:change a remote URL' ) _describe 'remote subcommand' remote_cmds ;; plumbing) local -a plumbing_cmds plumbing_cmds=( 'ls-files:list tracked files' 'cat-file:show raw object content' 'hash-object:compute object hash' 'merge-base:find common ancestor' 'rev-parse:resolve a ref to a SHA' ) _describe 'plumbing subcommand' plumbing_cmds ;; commit) _arguments \ '(-m --message)'{-m,--message}'[commit message]:message' \ '(-a --all)'{-a,--all}'[stage all changes before committing]' \ '--amend[amend the previous commit]' \ '--no-edit[reuse previous commit message]' ;; *) _files ;; esac ;; esac } _muse "$@"