OILS / doc / lib-osh.md View on Github | oilshell.org

100 lines, 59 significant
1---
2in_progress: yes
3default_highlighter: oils-sh
4---
5
6OSH Standard Library - Tiny Code, Evolved Over Years
7===========
8
9The [OSH][] standard library runs under both OSH and bash. ([YSH][] has a
10separate standard library.)
11
12This doc briefly describes a few hundred lines of code, documented in the Oils
13reference:
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
27I use shell as a quick / iterative / incremental development environment.
28
29I use "task files" and write down everything I do, so I don't forget them.
30
31They 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
50Trivial functions I use all the time.
51
52### bash-strict
53
54Catch errors.
55
56Saves you some boilerplate.
57
58### no-quotes
59
60Test 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
73May 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
83We commonly use this idiom:
84
85 REPO_ROOT=$(cd $(dirname $0)/..; pwd)
86
87But there is no library for it, because there's no standard way for it. Other
88variants I've seen:
89
90 pwd -P # we use pwd
91 readlink -f $0
92
93That is, there's not one way to do it when symlinks are involved.
94
95Most of our scripts must be run from repo root, and there are no symlinks to
96them.
97
98(Note that in OSH or YSH you can use `$_this_dir` instead of `$REPO_ROOT`, but
99it's not available in bash.)
100