1 # Oil user feedback
2
3 # From Zulip:
4 #
5 # https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/Experience.20using.20oil
6
7 #### setvar
8
9 # This seems to work as expected?
10
11 proc get_opt(arg, :out) {
12 setvar out = $arg
13 }
14 var a = ''
15 get_opt a 'lol'
16 echo hi
17 ## status: 1
18 ## STDOUT:
19 ## END
20
21 #### != operator
22 var a = 'bar'
23
24 # NOTE: a != foo is idiomatic)
25 if ($a != 'foo') {
26 echo 'not equal'
27 }
28
29 if ($a != 'bar') {
30 echo 'should not get here'
31 }
32
33 ## STDOUT:
34 not equal
35 ## END
36
37
38 #### elif bug
39 if (true) {
40 echo A
41 } elif (true) {
42 echo B
43 } elif (true) {
44 echo C
45 } else {
46 echo else
47 }
48 ## STDOUT:
49 A
50 ## END
51
52 #### global vars
53 builtin set -u
54
55 main() {
56 source $REPO_ROOT/spec/testdata/global-lib.sh
57 }
58
59 main
60 test_func
61
62 ## status: 1
63 ## STDOUT:
64 ## END
65
66 #### Julia port
67
68 # https://lobste.rs/s/ritbgc/what_glue_languages_do_you_use_like#c_nhikri
69 #
70 # See bash counterpart in spec/blog1.test.sh
71
72 git-branch-merged() {
73 cat <<EOF
74 foo
75 * bar
76 baz
77 master
78 EOF
79 }
80
81 # With bash-style readarray. The -t is annoying.
82 git-branch-merged | while read --line {
83 # Note: this can't be 'const' because const is dynamic like 'readonly'. And
84 # we don't have block scope.
85 var line = _line.strip() # removing leading space
86 if (line != 'master' and not line.startswith('*')) {
87 echo $line
88 }
89 } | readarray -t :branches
90
91 if (len(branches) == 0) {
92 echo "No merged branches"
93 } else {
94 write git branch -D @branches
95 }
96
97 # With "push". Hm read --lines isn't bad.
98 var branches2 = %()
99 git-branch-merged | while read --line {
100 var line2 = _line.strip() # removing leading space
101 if (line2 != 'master' and not line2.startswith('*')) {
102 push :branches2 $line2
103 }
104 }
105
106 write -- ___ @branches2
107
108 ## STDOUT:
109 git
110 branch
111 -D
112 foo
113 baz
114 ___
115 foo
116 baz
117 ## END
118
119 #### readonly in loop: explains why const doesn't work
120
121 # TODO: Might want to change const in Oil...
122 # bash actually prevents assignment and prints a warning, DOH.
123
124 seq 3 | while read -r line; do
125 readonly stripped=${line//1/x}
126 #declare stripped=${line//1/x}
127 echo $stripped
128 done
129 ## status: 1
130 ## STDOUT:
131 x
132 ## END
133
134