gunk-dev/the-valley

_valley

sourceaab236c3601amain's published tip history
1.7 KiB
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 'checks:print the checks a change owes under the composed policy'
15 'tail:watch bus events scroll by'
16 'replay:publish ref-updated events for the current refs of a repo'
17 'help:show help'
18 )
19 _describe -t verbs 'valley verb' verbs
20 elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then
21 _files -/
22 elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then
23 local -a opts=(
24 '--schema:the policy schema to compose against'
25 '--instance:the instance policy layer directory'
26 '--project:the project policy layer directory'
27 )
28 _describe -t options 'valley checks option' opts
29 elif (( CURRENT == 3 )) && [[ ${words[2]} == review ]]; then
30 # Branches on origin not merged into origin/main, origin/ prefix
31 # stripped, origin/HEAD + origin/main excluded. Silent outside a git
32 # repo — no errors mid-typing.
33 local -a branches
34 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
35 --format='%(refname:short)' --no-merged=origin/main 2>/dev/null)"})
36 branches=(${branches:#origin/HEAD})
37 branches=(${branches:#origin/main})
38 branches=(${branches#origin/})
39 (( ${#branches} )) && compadd -a branches
40 fi
41}
42
43_valley "$@"