OILS / doc / ref / chap-plugin.md View on Github | oils.pub

157 lines, 90 significant
1---
2title: Plugins and Hooks (Oils Reference)
3all_docs_url: ..
4body_css_class: width40
5default_highlighter: oils-sh
6preserve_anchor_case: yes
7---
8
9<div class="doc-ref-header">
10
11[Oils Reference](index.html) &mdash;
12Chapter **Plugins and Hooks**
13
14</div>
15
16This chapter describes extension points for OSH and YSH.
17
18<span class="in-progress">(in progress)</span>
19
20<div id="dense-toc">
21</div>
22
23## Signals
24
25### SIGTERM
26
27SIGTERM is the default signal sent by `kill`. It asks a process to terminate.
28
29You can register a SIGTERM handler with the [trap][] builtin.
30
31[trap]: chap-builtin-cmd.html#trap
32
33### SIGINT
34
35SIGINT is usually generated by Ctrl-C. It interrupts what the shell is doing
36and returns to the prompt.
37
38You can register a SIGINT handler with the [trap][] builtin.
39
40### SIGQUIT
41
42SIGQUIT is usually generated by Ctrl-\.
43
44### SIGTTIN
45
46Used by the job control implementation.
47
48### SIGTTOU
49
50Used by the job control implementation.
51
52### SIGWINCH
53
54Oils receives this signal when the terminal window size changes.
55
56## Traps
57
58### DEBUG
59
60Runs code before "leaf" commands, like
61
62 echo hi
63 a=b
64 [[ x -eq y ]]
65 (( a = 42 ))
66
67But not before `{`:
68
69 { echo one; echo two; }
70
71---
72
73See the [Quirks doc](../quirks.html) for an interaction between the `DEBUG`
74trap, pipelines, and interactive shells.
75
76### ERR
77
78The `ERR` trap runs when a command fails, i.e. in the situations where `set -o
79errexit` aka `set -e` exits the shell.
80
81To enable it in functions and subshells, use `set -o errtrace`, aka `set -E`.
82
83It's designed to be compatible with bash.
84
85### EXIT
86
87TODO
88
89### RETURN
90
91TODO
92
93## Words
94
95### PS1
96
97The `PS1` variable controls the first line of the shell prompt. It is designed
98to be bash-compatible.
99
100See the [Bash Manual > Controlling the Prompt][bash-prompt].
101
102[bash-prompt]: https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html
103
104Note that the general `\D{format}` is implemented, but some of the more
105specific time formats are not implemented.
106
107### PS2
108
109Second line of the shell prompt (unimplemented).
110
111### PS3
112
113For the `select` builtin (unimplemented).
114
115### PS4
116
117The prefix of each line of output in `set -x` aka `set -o xtrace`. The leading
118character is special.
119
120## Completion
121
122### complete
123
124The [complete][] builtin calls back into the shell evaluator to create
125candidate strings for autocompletion:
126
127- `-C` is an external command that's executed
128- `-F` is the name of a shell function name that's run
129- `-W` is a word list that's evalutaed
130
131[complete]: chap-builtin-cmd.html#complete
132
133## Other Plugin
134
135### PROMPT_COMMAND
136
137A command that's executed before each prompt.
138
139This feature is taken from [bash]($xref).
140
141## YSH
142
143### renderPrompt()
144
145Users may define this func to customize their prompt.
146
147The func should take the global `value.IO` instance, and return a prompt string
148(type `value.Str`).
149
150To construct the prompt, it can make calls like
151[`io->promptVal('$')`]($chap-type-method:promptVal).
152
153To render the prompt, YSH first checks if this function exists. Otherwise, it
154uses [`$PS1`]($chap-plugin:PS1) with a `ysh` prefix.
155
156<!-- note: doctools/cmark.py turns promptVal -> promptval -->
157