gunk-dev/the-valley

_valley

source3be481bd0edfmain's published tip history
1.9 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 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]} == -* ]]; then
24 local -a opts=(
25 '--schema:the policy schema to compose against'
26 '--instance:the instance policy layer directory'
27 '--project:the project policy layer directory'
28 )
29 _describe -t options 'valley checks option' opts
30 elif (( CURRENT == 3 )) && [[ ${words[2]} == review || ${words[2]} == status ]]; then
31 # Cached topic branches on origin. Review filters out merged branches;
32 # status needs those too. Silent outside a git repo — no errors
33 # mid-typing.
34 local -a branches selection
35 selection=()
36 [[ ${words[2]} == review ]] && selection=(--no-merged=origin/main)
37 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
38 --format='%(refname)' "${selection[@]}" 2>/dev/null)"})
39 branches=(${branches:#refs/remotes/origin/HEAD})
40 branches=(${branches:#refs/remotes/origin/main})
41 branches=(${branches#refs/remotes/origin/})
42 (( ${#branches} )) && compadd -a branches
43 fi
44}
45
46_valley "$@"