1 | ---
|
2 | in_progress: yes
|
3 | default_highlighter: oils-sh
|
4 | ---
|
5 |
|
6 | OSH Standard Library - Tiny Code, Evolved Over Years
|
7 | ===========
|
8 |
|
9 | The [OSH][] standard library runs under both OSH and bash. ([YSH][] has a
|
10 | separate standard library.)
|
11 |
|
12 | This doc briefly describes a few hundred lines of code, documented in the Oils
|
13 | reference:
|
14 |
|
15 | - [Oils Reference](ref/) > [OSH Table of Contents](ref/toc-osh.html)
|
16 |
|
17 |
|
18 | [OSH]: $xref
|
19 | [YSH]: $xref
|
20 |
|
21 |
|
22 | <div id="toc">
|
23 | </div>
|
24 |
|
25 | ## Intro
|
26 |
|
27 | I use shell as a quick / iterative / incremental development environment.
|
28 |
|
29 | I use "task files" and write down everything I do, so I don't forget them.
|
30 |
|
31 | They evolve and grew over time, but are still small.
|
32 |
|
33 | ### Example of Task File
|
34 |
|
35 | : ${LIB_OSH=stdlib/osh} # to share with bash
|
36 | source $LIB_OSH/bash-strict.sh
|
37 | source $LIB_OSH/task-five.sh
|
38 |
|
39 | test-foo() {
|
40 | echo hi
|
41 | }
|
42 |
|
43 | task-five "$@"
|
44 |
|
45 |
|
46 | ## List of Libraries
|
47 |
|
48 | ### two
|
49 |
|
50 | Trivial functions I use all the time.
|
51 |
|
52 | ### bash-strict
|
53 |
|
54 | Catch errors.
|
55 |
|
56 | Saves you some boilerplate.
|
57 |
|
58 | ### no-quotes
|
59 |
|
60 | Test framework without extra levels of quoting. Compare to git sharness.
|
61 |
|
62 | nq-capture
|
63 | nq-capture-2
|
64 | nq-assert
|
65 |
|
66 | ### byo-server
|
67 |
|
68 | - Test discovery
|
69 | - Probably:
|
70 | - task discovery
|
71 | - auto-completion
|
72 |
|
73 | May want to fold this into task-five.
|
74 |
|
75 | ### task-five
|
76 |
|
77 | - Task files
|
78 |
|
79 | ## Appendix
|
80 |
|
81 | ### Why no standard way to set `$REPO_ROOT`?
|
82 |
|
83 | We commonly use this idiom:
|
84 |
|
85 | REPO_ROOT=$(cd $(dirname $0)/..; pwd)
|
86 |
|
87 | But there is no library for it, because there's no standard way for it. Other
|
88 | variants I've seen:
|
89 |
|
90 | pwd -P # we use pwd
|
91 | readlink -f $0
|
92 |
|
93 | That is, there's not one way to do it when symlinks are involved.
|
94 |
|
95 | Most of our scripts must be run from repo root, and there are no symlinks to
|
96 | them.
|
97 |
|
98 | (Note that in OSH or YSH you can use `$_this_dir` instead of `$REPO_ROOT`, but
|
99 | it's not available in bash.)
|
100 |
|