github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/user-guide/interactive-shell.md (about)

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