1 | stdlib/
|
2 | =======
|
3 |
|
4 | Ideas for shell functions that could be in here:
|
5 |
|
6 | - Version comparison: https://github.com/oilshell/oil/issues/683
|
7 | - An automated way to download the latest version of Oil: https://github.com/oilshell/oil/issues/463
|
8 | - Maybe functions to lazily download documentation too?
|
9 | - `errexit` utilities: https://github.com/oilshell/oil/issues/474
|
10 |
|
11 | ## Notes on Contents
|
12 |
|
13 | This should be in doc/ref/chap-stdlib.md
|
14 |
|
15 | two.sh # The two functions I actually use
|
16 | byo-server-lib.sh # for using bash to test scripts
|
17 | # you need a client too
|
18 |
|
19 | YSH
|
20 |
|
21 | args.ysh
|
22 | testing.ysh # should these be assertions?
|
23 |
|
24 | stream.ysh
|
25 | table.ysh
|
26 |
|
27 | math.ysh # abs, max, min - TODO: sum
|
28 | list.ysh # any all sum
|
29 | funcs.ysh # identity - not that useful
|
30 |
|
31 | prelude.ysh # todo pass, hm
|
32 |
|
33 | ## What We Actually Use in Oils
|
34 |
|
35 | source stdlib/two.sh # I definitely use this
|
36 | source stdlib/bash-strict.sh # inherit_errexit
|
37 |
|
38 | source stdlib/taskfile.sh # questionable?
|
39 | # needs function docstring support
|
40 | # needs file docstring support
|
41 |
|
42 | source stdlib/byo-server-lib.sh # convert more of these
|
43 |
|
44 | ## Task Files Templates
|
45 |
|
46 | Problem: user scripts wouldn't run under bash:
|
47 |
|
48 | # Docstring
|
49 | source --builtin bash-strict.sh
|
50 | source --builtin two.sh
|
51 | source --builtin taskfile.sh
|
52 |
|
53 | foo() {
|
54 | echo todo
|
55 | }
|
56 |
|
57 | taskfile "$@"
|
58 |
|
59 | Test:
|
60 |
|
61 | # Docstring
|
62 | source --builtin bash-strict.sh
|
63 | source --builtin two.sh
|
64 | source --builtin byo-server-lib.sh
|
65 |
|
66 | source test/common.sh # assertions
|
67 |
|
68 | test-foo() {
|
69 | echo TODO
|
70 | }
|
71 |
|
72 | byo-maybe-main
|
73 |
|
74 | Command usage:
|
75 |
|
76 | byo test stdlib/TEST.sh
|
77 |
|
78 | I think that is reasonable.
|
79 |
|
80 | Polyglot:
|
81 |
|
82 | if test -n "${OILS_VERSION:-}"; then
|
83 | prefix='--builtin '
|
84 | else
|
85 | prefix='stdlib'
|
86 | fi
|
87 |
|
88 | source ${prefix}two.sh
|
89 | source ${prefix}bash-strict.sh
|
90 |
|
91 | Honestly I think this is better.
|
92 |
|
93 | # Bootstrapping trick, to
|
94 | # To avoid self-hosting
|
95 | if test -z "${OILS_VERSION:-}"; then
|
96 | OSH_LIB='stdlib'
|
97 | fi
|
98 |
|
99 | source $OSH_LIB/bash-strict.sh
|
100 | source $OSH_LIB/two.sh
|
101 | source $OSH_LIB/taskfile.sh
|
102 |
|
103 | source $OSH_LIB/byo-server-lib.sh
|
104 |
|
105 | # source /osh-lib/foo # refers to the actual directory
|
106 |
|
107 | source $OSH_LIB/bash-strict.sh
|
108 | source ///osh-lib/bash-strict.sh
|
109 |
|
110 | # Does not work - this refers to a real dir
|
111 | source /osh-lib/bash-strict.sh
|
112 |
|
113 |
|
114 | use $YSH_LIB/args.ysh { pick parser }
|
115 |
|
116 | use $YSH_LIB/arg-parser.ysh
|
117 | arg-parser (&x) {
|
118 | flag --fo x
|
119 | flag --fo x
|
120 | }
|
121 |
|
122 | use $YSH_LIB/table.ysh { pick table split-by }
|
123 |
|
124 | Repo:
|
125 |
|
126 | oils/
|
127 | stdlib/
|
128 | osh/
|
129 | two.sh
|
130 | bash-strict.sh
|
131 | taskfile.sh
|
132 | ysh/
|
133 | args.ysh
|
134 | table.ysh
|
135 | stream.ysh
|
136 |
|
137 |
|
138 |
|
139 | ## Polyfill ideas
|
140 |
|
141 | ### From Soil - Fix SSH and Bernstein chaining
|
142 |
|
143 | ssh $USER@$HOST "$(argv-to-str "$@")"
|
144 |
|
145 | which is simply:
|
146 |
|
147 | ssh $USER@$HOST "$(printf '%q ' "$@")"
|
148 |
|
149 | Though it would be more convenient as:
|
150 |
|
151 | quotefix ssh $USER@$HOST --- "$@"
|
152 |
|
153 | The --- means you are ending the normal args?
|
154 |
|
155 |
|
156 | Do we also need one for scp? On OS X it seems more weird.
|
157 |
|
158 | ### exit 255 for xargs?
|
159 |
|
160 | That's the special exit code to ABORT, hm.
|
161 |
|
162 | But I think 'each' will not do this? We should concentrate on that.
|
163 |
|
164 |
|
165 | ### strict mode
|
166 |
|
167 | Not sure it makes sense to source anything for this.
|
168 |
|
169 | shopt --set strict:all || true 2>&/dev/null
|