diff options
| author | Steven Xu <stevenxxiu@users.noreply.github.com> | 2023-03-27 01:44:06 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-26 15:44:06 +0100 |
| commit | a7cb21a51b393b436c0ca7e09c892ebb3c597ad0 (patch) | |
| tree | d55d1ad07d5d01ccac6f5100bf4d131da748537c /src/shell | |
| parent | Add musl build (#809) (diff) | |
| download | atuin-a7cb21a51b393b436c0ca7e09c892ebb3c597ad0.zip | |
feat: add *Nushell* support (#788)
* feat: add *Nushell* support
* refactor: use `sh` to swap `STDOUT` and `STDERR` instead of using a temporary file
* feat: include both keybindings, with the current REPL buffer passed to *Atuin*'s
* feat: don't record commands run by keybindings
Diffstat (limited to 'src/shell')
| -rw-r--r-- | src/shell/atuin.nu | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/shell/atuin.nu b/src/shell/atuin.nu new file mode 100644 index 00000000..f8886fc9 --- /dev/null +++ b/src/shell/atuin.nu @@ -0,0 +1,41 @@ +# Source this in your ~/.config/nushell/config.nu +let-env ATUIN_SESSION = (atuin uuid) + +# Magic token to make sure we don't record commands run by keybindings +let ATUIN_KEYBINDING_TOKEN = $"# (random uuid)" + +let _atuin_pre_execution = {|| + let cmd = (commandline) + if not ($cmd | str starts-with $ATUIN_KEYBINDING_TOKEN) { + let-env ATUIN_HISTORY_ID = (atuin history start -- $cmd) + } +} + +let _atuin_pre_prompt = {|| + let last_exit = $env.LAST_EXIT_CODE + if 'ATUIN_HISTORY_ID' not-in $env { + return + } + with-env { RUST_LOG: error } { + atuin history end --exit $last_exit -- $env.ATUIN_HISTORY_ID | null + } +} + +def _atuin_search_cmd [...flags: string] { + [ + $ATUIN_KEYBINDING_TOKEN, + ([ + `commandline (sh -c 'RUST_LOG=error atuin search `, + $flags, + ` -i -- "$0" 3>&1 1>&2 2>&3' (commandline))`, + ] | flatten | str join ''), + ] | str join "\n" +} + +let-env config = ( + $env.config | upsert hooks ( + $env.config.hooks + | upsert pre_execution ($env.config.hooks.pre_execution | append $_atuin_pre_execution) + | upsert pre_prompt ($env.config.hooks.pre_prompt | append $_atuin_pre_prompt) + ) +) |
