| 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 approve, reject, or skip' |
| 14 | 'approve:approve a change without paging it, filing its integration request' |
| 15 | 'rebase:rebase a change onto origin/main and push it with a lease' |
| 16 | 'status:read the integration result for a branch from origin' |
| 17 | 'checks:print the checks a change owes under the composed policy' |
| 18 | 'tail:watch bus events scroll by' |
| 19 | 'replay:publish ref-updated events for the current refs of a repo' |
| 20 | 'help:show help' |
| 21 | ) |
| 22 | _describe -t verbs 'valley verb' verbs |
| 23 | elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then |
| 24 | _files -/ |
| 25 | elif [[ ${words[2]} == checks && ${words[CURRENT-1]} == --cost ]]; then |
| 26 | compadd quick slow |
| 27 | elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then |
| 28 | local -a opts=( |
| 29 | '--schema:the policy schema to compose against' |
| 30 | '--instance:the instance policy layer directory' |
| 31 | '--project:the project policy layer directory' |
| 32 | '--names:print only the owed check names, one per line' |
| 33 | '--cost:with --names, only the quick or the slow checks' |
| 34 | ) |
| 35 | _describe -t options 'valley checks option' opts |
| 36 | elif [[ ${words[2]} == status && ${words[CURRENT]} == -* ]]; then |
| 37 | local -a opts=('--json:print the status as one valley-status/v1 JSON object') |
| 38 | _describe -t options 'valley status option' opts |
| 39 | elif [[ ${words[2]} == (review|approve|rebase|status) ]] \ |
| 40 | && { (( CURRENT == 3 )) || [[ ${words[2]} == status ]]; }; then |
| 41 | # Cached topic branches on origin. Review, approve and rebase filter |
| 42 | # out merged branches; status needs those too. Silent outside a git |
| 43 | # repo — no errors mid-typing. |
| 44 | local -a branches selection |
| 45 | selection=() |
| 46 | [[ ${words[2]} != status ]] && selection=(--no-merged=origin/main) |
| 47 | branches=(${(f)"$(git for-each-ref refs/remotes/origin \ |
| 48 | --format='%(refname)' "${selection[@]}" 2>/dev/null)"}) |
| 49 | branches=(${branches:#refs/remotes/origin/HEAD}) |
| 50 | branches=(${branches:#refs/remotes/origin/main}) |
| 51 | branches=(${branches#refs/remotes/origin/}) |
| 52 | (( ${#branches} )) && compadd -a branches |
| 53 | fi |
| 54 | } |
| 55 | |
| 56 | _valley "$@" |