github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/gen/user-guide/interactive-shell.inc.md (about) 1 {{ if env "DOCGEN_TARGET=" }}<h2>Table of Contents</h2> 2 3 <div id="toc"> 4 5 - [Overview](#overview) 6 - [readline](#readline) 7 - [Hotkeys](#hotkeys) 8 - [Autocompletion](#autocompletion) 9 - [Syntax Completion](#syntax-completion) 10 - [Syntax Highlighting](#syntax-highlighting) 11 - [Spellchecker](#spellchecker) 12 - [Hint Text](#hint-text) 13 - [Configuring Hint Text Colour](#configuring-hint-text-colour) 14 - [Custom Hint Text Statuses](#custom-hint-text-statuses) 15 - [Starship Example](#starship-example) 16 - [Disabling Hint Text](#disabling-hint-text) 17 - [Preview](#preview) 18 - [Autocomplete Preview](#autocomplete-preview) 19 - [Command Line Preview](#command-line-preview) 20 - [Safer Pasting](#safer-pasting) 21 - [Smarter Error Messages](#smarter-error-messages) 22 23 </div> 24 25 {{ end }} 26 27 ## Overview 28 29 Aside from Murex being carefully designed with scripting in mind, the 30 interactive shell itself is also built around productivity. To achieve this 31 we wrote our own readline library. Below is an example of that library in use: 32 33 [](https://asciinema.org/a/232714) 34 35 The above demo includes the following features of Murex's bespoke readline 36 library: 37 38 * hint text - blue status text below the prompt (the colour is configurable) 39 * syntax highlighting (albeit there isn’t much syntax to highlight in the 40 example). This can also be turned off if your preference is to have colours 41 disabled 42 * tab-completion in gridded mode (seen when typing `cd`) 43 * tab-completion in list view (seen when selecting a process name to `kill` 44 where the process ID was substituted when selected) 45 * searching through the tab-completion suggestions (seen in both `cd` and 46 `kill` - enabled by pressing `[ctrl]`+`[f]`) 47 * line editing using $EDITOR (`vi` in the example - enabled by pressing `[esc]` 48 followed by `[v]`) 49 * readline’s warning before pasting multiple lines of data into the buffer and 50 the preview option that’s available as part of the aforementioned warning 51 * and VIM keys (enabled by pressing `[esc]`) 52 53 ## readline 54 55 Murex uses a custom `readline` library to enable support for new features in 56 addition to the existing uses you'd normally expect from a shell. It is because 57 of this, Murex provides one of the best user experiences of any of the shells 58 available today. 59 60 ## Hotkeys 61 62 {{ if env "DOCGEN_TARGET=vuepress" }} 63 <!-- markdownlint-disable --> 64 <a href="terminal-keys.html" alt="supported hotkeys"><img src="/keyboard.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/></a> 65 <!-- markdownlint-restore --> 66 {{ end }} 67 68 A full breakdown of supported hotkeys is available in the [terminal-keys](terminal-keys.md) 69 guide. 70 71 ## Autocompletion 72 73 Autocompletion happen when you press `[tab]` and will differ slightly depending 74 on what is defined in `autocomplete` and whether you use the traditional 75 [POSIX pipe token](../parser/pipe-posix.md), `|`, or the [arrow pipe](../parser/pipe-arrow.md), 76 `->`. 77 78 The `|` token will behave much like any other shell however `->` will offer 79 suggestions with matching data types (as seen in `runtime --methods`). This is 80 a way of helping highlight commands that naturally follow after another in a 81 pipeline. Which is particularly important in Murex as it introduces data 82 types and dozens of new builtins specifically for working with data structures 83 in an intelligent and readable yet succinct way. 84 85 You can add your own commands and functions to Murex as methods by defining 86 them with `method`. For example if we were to add `jq` as a method: 87 88 ``` 89 method define jq { 90 "Stdin": "json", 91 "Stdout": "@Any" 92 } 93 ``` 94 95 {{ if env "DOCGEN_TARGET=vuepress" }} 96 <!-- markdownlint-disable --> 97 <br/> 98 <img src="/screenshot-ps-select.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 99 <!-- markdownlint-restore --> 100 {{ end }} 101 102 ## Syntax Completion 103 104 Like with most IDEs, Murex will auto close brackets et al. 105 106 [](https://asciinema.org/a/408029) 107 108 ## Syntax Highlighting 109 110 Pipelines in the interactive terminal are syntax highlighted. This is similar 111 to what one expects from an IDE. 112 113 Syntax highlighting can be disabled by running: 114 115 ``` 116 config set shell syntax-highlighting off 117 ``` 118 119 ## Spellchecker 120 121 Murex supports inline spellchecking, where errors are underlined. For example 122 123 [](https://asciinema.org/a/408024) 124 125 This might require some manual steps to enable, please see the [spellcheck user guide](spellcheck.md) 126 for more details. 127 128 {{ if env "DOCGEN_TARGET=vuepress" }} 129 <!-- markdownlint-disable --> 130 <img src="/screenshot-spellchecker.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 131 <!-- markdownlint-restore --> 132 {{ end }} 133 134 ## Hint Text 135 136 The **hint text** is a (typically) blue status line that appears directly below 137 your prompt. The idea behind the **hint text** is to provide clues to you as 138 type instructions into the prompt; but without adding distractions. It is there 139 to be used if you want it while keeping out of the way when you don't want it. 140 141 {{ if env "DOCGEN_TARGET=vuepress" }} 142 <!-- markdownlint-disable --> 143 <img src="/screenshot-hint-text-rsync.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 144 <!-- markdownlint-restore --> 145 {{ end }} 146 147 ### Configuring Hint Text Colour 148 149 By default the **hint text** will appear blue. This is also customizable: 150 151 ``` 152 » config get shell hint-text-formatting 153 {BLUE} 154 ``` 155 156 The formatting config takes a string and supports [ANSI constants](ansi.md). 157 158 It is also worth noting that if colour is disabled then the **hint text** will 159 not be coloured even if **hint-text-formatting** includes colour codes: 160 161 ``` 162 » config set shell color false 163 ``` 164 165 (please note that **syntax highlighting** is unaffected by the above config) 166 167 ### Custom Hint Text Statuses 168 169 There is a lot of behavior hardcoded into Murex like displaying the full path 170 to executables and the values of variables. However if there is no status to be 171 displayed then Murex can fallback to a default **hint text** status. This 172 default is a user defined function. At time of writing this document the author 173 has the following function defined: 174 175 ``` 176 config set shell hint-text-func { 177 trypipe <!null> { 178 git status --porcelain -b -> set gitstatus 179 $gitstatus -> head -n1 -> regexp 's/^## //' -> regexp 's/\.\.\./ => /' 180 } 181 catch { 182 out "Not a git repository." 183 } 184 } 185 ``` 186 187 ...which produces a colorized status that looks something like the following: 188 189 ``` 190 develop => origin/develop 191 ``` 192 193 {{ if env "DOCGEN_TARGET=vuepress" }} 194 ### Starship Example 195 196 The following screenshot is of a custom hint text using Starship: 197 198 <!-- markdownlint-disable --> 199 <img src="/screenshot-hint-starship.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 200 <!-- markdownlint-restore --> 201 202 Source: [https://github.com/orefalo/murex-module-starship](https://github.com/orefalo/murex-module-starship) 203 {{ end }} 204 205 ### Disabling Hint Text 206 207 It is enabled by default but can be disabled if you prefer a more minimal 208 prompt: 209 210 ``` 211 » config set shell hint-text-enabled false 212 ``` 213 214 ## Preview 215 216 Murex supports a couple of full screen preview modes: 217 218 * Autocomplete Preview ([read more](#autocomplete-preview)) 219 * Command Line Preview ([read more](#command-line-preview)) 220 221 ### Autocomplete Preview 222 223 > Enabled via `[f1]` 224 225 This displays a more detailed view of each parameter you're about to pass to a 226 command, without you having to run that command nor leave the half-completed 227 command line. 228 229 It can display: 230 * `man` pages 231 * custom guides like https://cheat.sh 232 * information about binary files 233 * contents of text files 234 * and even images too! 235 236 {{ if env "DOCGEN_TARGET=vuepress" }} 237 <!-- markdownlint-disable --> 238 <img src="/screenshot-preview-man-page.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 239 <br/> 240 <img src="/screenshot-preview-image.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 241 <!-- markdownlint-restore --> 242 {{ end }} 243 244 ### Command Line Preview 245 246 > Enabled via `[f9]` 247 248 The Command Line Preview allows you to view the output of a command line while 249 you're still writing it. This interactivity removes the trial-and-error from 250 working with complicated command line incantations. For example parsing parsing 251 complex documents like machine generated JSON becomes very easy. 252 253 {{ if env "DOCGEN_TARGET=vuepress" }} 254 <!-- markdownlint-disable --> 255 <img src="/screenshot-preview-command-line.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 256 <!-- markdownlint-restore --> 257 {{ end }} 258 259 This does come with some risks because most command line operations change you 260 systems state. However Murex comes with some guardrails here too: 261 262 * Each command in the pipeline is cached. So if a command's parameters are 263 changed, Murex only needs to re-run the commands _from_ the changed 264 parameter onwards. 265 266 * Each time there is a change in the commands themselves, for example a new 267 command added to the pipeline, you are requested to press `[f9]` to re-run 268 the entire pipeline. 269 270 * The only commands considered "safe" for auto-execution if any parameters do 271 change are those marked as "safe" in `config`. For example: 272 ``` 273 » config get shell safe-commands -> tail -n5 274 td 275 cut 276 jobs 277 select 278 dig 279 ``` 280 281 ## Safer Pasting 282 283 A common behaviour for command line users is to copy and paste data into the 284 terminal emulator. Some shells like Zsh support [Bracketed paste](https://en.wikipedia.org/wiki/Bracketed-paste) 285 but that does a pretty poor job of protecting you against the human error of 286 pasting potentially dangerous contents from an invisible clipboard. 287 288 Where Murex differs is that any multi-line text pasted will instantly display 289 a warning prompt with one of the options being to view the contents that you're 290 about to execute. 291 292 {{ if env "DOCGEN_TARGET=vuepress" }} 293 <!-- markdownlint-disable --> 294 <img src="/screenshot-paste-safety.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 295 <!-- markdownlint-restore --> 296 {{ end }} 297 298 This gives you piece-of-mind that you are executing the right clipboard content 299 rather than something else you copied hours ago and forgotten about. 300 301 ## Smarter Error Messages 302 303 Errors messages in most shells suck. That's why Murex has taken extra care to 304 give you as much useful detail as it can. 305 306 {{ if env "DOCGEN_TARGET=vuepress" }} 307 <!-- markdownlint-disable --> 308 <img src="/screenshot-error-messages.png?v={{ env "COMMITHASHSHORT" }}" class="centre-image"/> 309 <!-- markdownlint-restore --> 310 {{ end }}