gunk-dev/the-valley

_valley

source6294c4478dabmain's published tip history
1.2 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 'help:show help'
15 )
16 _describe -t verbs 'valley verb' verbs
17 elif (( CURRENT == 3 )) && [[ ${words[2]} == review ]]; then
18 # Branches on origin not merged into origin/main, origin/ prefix
19 # stripped, origin/HEAD + origin/main excluded. Silent outside a git
20 # repo — no errors mid-typing.
21 local -a branches
22 branches=(${(f)"$(git for-each-ref refs/remotes/origin \
23 --format='%(refname:short)' --no-merged=origin/main 2>/dev/null)"})
24 branches=(${branches:#origin/HEAD})
25 branches=(${branches:#origin/main})
26 branches=(${branches#origin/})
27 (( ${#branches} )) && compadd -a branches
28 fi
29}
30
31_valley "$@"