| 1 | #compdef valley |
| 2 | # zsh completion for valley. The verb list mirrors the case statement in |
| 3 | # bin/valley — update both together. |
| 4 | # |
| 5 | # NEVER fetch from here: completion runs on every <TAB> and must be instant. |
| 6 | # Candidates come from the remote-tracking refs of the last fetch; valley's |
| 7 | # own verbs fetch before acting, so stale candidates cost nothing. |
| 8 | |
| 9 | _valley() { |
| 10 | if (( CURRENT == 2 )); then |
| 11 | local -a verbs=( |
| 12 | 'pending:list branches on origin not merged into origin/main' |
| 13 | 'review:page through a branch, then ask, reject, or skip' |
| 14 | 'status:read the integration result for a branch from origin' |
| 15 | 'checks:print the checks a change owes under the composed policy' |
| 16 | 'tail:watch bus events scroll by' |
| 17 | 'replay:publish ref-updated events for the current refs of a repo' |
| 18 | 'help:show help' |
| 19 | ) |
| 20 | _describe -t verbs 'valley verb' verbs |
| 21 | elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then |
| 22 | _files -/ |
| 23 | elif [[ ${words[2]} == checks && ${words[CURRENT-1]} == --cost ]]; then |
| 24 | compadd quick slow |
| 25 | elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then |
| 26 | local -a opts=( |
| 27 | '--schema:the policy schema to compose against' |
| 28 | '--instance:the instance policy layer directory' |
| 29 | '--project:the project policy layer directory' |
| 30 | '--names:print only the owed check names, one per line' |
| 31 | '--cost:with --names, only the quick or the slow checks' |
| 32 | ) |
| 33 | _describe -t options 'valley checks option' opts |
| 34 | elif (( CURRENT == 3 )) && [[ ${words[2]} == review || ${words[2]} == status ]]; then |
| 35 | # Cached topic branches on origin. Review filters out merged branches; |
| 36 | # status needs those too. Silent outside a git repo — no errors |
| 37 | # mid-typing. |
| 38 | local -a branches selection |
| 39 | selection=() |
| 40 | [[ ${words[2]} == review ]] && selection=(--no-merged=origin/main) |
| 41 | branches=(${(f)"$(git for-each-ref refs/remotes/origin \ |
| 42 | --format='%(refname)' "${selection[@]}" 2>/dev/null)"}) |
| 43 | branches=(${branches:#refs/remotes/origin/HEAD}) |
| 44 | branches=(${branches:#refs/remotes/origin/main}) |
| 45 | branches=(${branches#refs/remotes/origin/}) |
| 46 | (( ${#branches} )) && compadd -a branches |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | _valley "$@" |