gunk-dev/the-valley

_valley

sourceb9e4021e9f34main's published tip history
3.1 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 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 change from origin'
17 'ready:mark a head of a branch ready as a new version of its change'
18 'withdraw:mark a ready change withdrawn'
19 'checks:print the checks a change owes under the composed policy'
20 'tail:watch bus events scroll by'
21 'replay:publish ref-updated events for the current refs of a repo'
22 'help:show help'
23 )
24 _describe -t verbs 'valley verb' verbs
25 elif (( CURRENT == 3 )) && [[ ${words[2]} == replay ]]; then
26 _files -/
27 elif [[ ${words[2]} == checks && ${words[CURRENT-1]} == --cost ]]; then
28 compadd quick slow
29 elif [[ ${words[2]} == checks && ${words[CURRENT]} == -* ]]; then
30 local -a opts=(
31 '--schema:the policy schema to compose against'
32 '--instance:the instance policy layer directory'
33 '--project:the project policy layer directory'
34 '--names:print only the owed check names, one per line'
35 '--cost:with --names, only the quick or the slow checks'
36 )
37 _describe -t options 'valley checks option' opts
38 elif [[ ${words[2]} == ready && ${words[CURRENT]} == -* ]]; then
39 local -a opts=(
40 '--head:the head to mark ready, already on origin'
41 '--change:the change ID to record the version under'
42 '--stamp:carry the change ID in the head as a Change-Id trailer'
43 )
44 _describe -t options 'valley ready option' opts
45 elif [[ ${words[2]} == ready && ${words[CURRENT-1]} == --(head|change) ]]; then
46 return
47 elif [[ ${words[2]} == status && ${words[CURRENT]} == -* ]]; then
48 local -a opts=('--json:print the status as one valley-status/v1 JSON object')
49 _describe -t options 'valley status option' opts
50 elif [[ ${words[2]} == (review|approve|rebase|status|ready) ]] \
51 && { (( CURRENT == 3 )) || [[ ${words[2]} == (status|ready) ]]; }; then
52 # Cached topic branches on origin. Review, approve, rebase and ready filter
53 # out merged branches; status needs those too. Silent outside a git
54 # repo — no errors mid-typing.
55 local -a branches selection
56 selection=()
57 [[ ${words[2]} != status ]] && selection=(--no-merged=origin/main)
58 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
59 --format='%(refname)' "${selection[@]}" 2>/dev/null)"})
60 branches=(${branches:#refs/remotes/origin/HEAD})
61 branches=(${branches:#refs/remotes/origin/main})
62 branches=(${branches#refs/remotes/origin/})
63 (( ${#branches} )) && compadd -a branches
64 fi
65}
66
67_valley "$@"