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