OILS / spec / testdata / ysh-user-feedback.sh View on Github | oilshell.org

52 lines, 23 significant
1# Called from spec/ysh-user-feedback
2#
3# Spec test framework reads code from stdin, which conflicts with read --line
4
5# https://lobste.rs/s/ritbgc/what_glue_languages_do_you_use_like#c_nhikri
6#
7# See bash counterpart in spec/blog1.test.sh
8
9git-branch-merged() {
10 cat <<EOF
11 foo
12* bar
13 baz
14 master
15EOF
16}
17
18# With bash-style readarray. The -t to remove trailing newline is annoying.
19git-branch-merged | while read -r line {
20 # Note: this can't be 'const' because const is dynamic like 'readonly'. And
21 # we don't have block scope.
22 var line = line => trim() # removing leading space
23
24 # with glob: line ~~ '\**' (awkward)
25 # with regex: line ~ / %start '*' / (not terrible, but somewhat complex)
26
27 if (line !== 'master' and not line => startsWith('*')) {
28 echo $line
29 }
30} | readarray -t branches
31
32# TODO: I think we want read --lines (&branches)? Then we don't need this
33# conversion.
34var branchList = :| "${branches[@]}" |
35
36if (len(branchList) === 0) {
37 echo "No merged branches"
38} else {
39 write git branch -D @branchList
40}
41
42# With "append". Hm read --lines isn't bad.
43var branches2 = :| |
44git-branch-merged | while read -r line {
45 var line2 = line => trim() # removing leading space
46 if (line2 !== 'master' and not line2 => startsWith('*')) {
47 append $line2 (branches2)
48 }
49}
50
51write -- ___ @branches2
52