| 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 integrate, reject, or skip' |
| 14 | 'tail:watch bus events scroll by' |
| 15 | 'replay:publish ref-updated events for the current refs of a repo' |
| 16 | 'help:show help' |
| 17 | ) |
| 18 | _describe -t verbs 'valley verb' verbs |
| 19 | elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then |
| 20 | _files -/ |
| 21 | elif (( CURRENT == 3 )) && [[ ${words[2]} == review ]]; then |
| 22 | # Branches on origin not merged into origin/main, origin/ prefix |
| 23 | # stripped, origin/HEAD + origin/main excluded. Silent outside a git |
| 24 | # repo — no errors mid-typing. |
| 25 | local -a branches |
| 26 | branches=(${(f)"$(git for-each-ref refs/remotes/origin \ |
| 27 | --format='%(refname:short)' --no-merged=origin/main 2>/dev/null)"}) |
| 28 | branches=(${branches:#origin/HEAD}) |
| 29 | branches=(${branches:#origin/main}) |
| 30 | branches=(${branches#origin/}) |
| 31 | (( ${#branches} )) && compadd -a branches |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | _valley "$@" |