aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/shell/atuin.nu
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-09 21:43:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-09 21:43:23 +0200
commit3223d93cb3c77ab02aa0a35f2a8314e447cee9a4 (patch)
tree3971a1f37f5fe3cadb747c5229a0d54e868e45e3 /crates/turtle/src/shell/atuin.nu
parentfix(client/sync): Pass through precise error on `SyncError::WrongKey` (diff)
downloadatuin-3223d93cb3c77ab02aa0a35f2a8314e447cee9a4.zip
chore: Separate daemon, client, server, and lib into crates
Diffstat (limited to 'crates/turtle/src/shell/atuin.nu')
-rw-r--r--crates/turtle/src/shell/atuin.nu121
1 files changed, 0 insertions, 121 deletions
diff --git a/crates/turtle/src/shell/atuin.nu b/crates/turtle/src/shell/atuin.nu
deleted file mode 100644
index d37457e4..00000000
--- a/crates/turtle/src/shell/atuin.nu
+++ /dev/null
@@ -1,121 +0,0 @@
-# Source this in your ~/.config/nushell/config.nu
-# minimum supported version = 0.93.0
-module compat {
- export def --wrapped "random uuid -v 7" [...rest] { atuin uuid }
-}
-use (if not (
- (version).major > 0 or
- (version).minor >= 103
-) { "compat" }) *
-
-if 'ATUIN_SESSION' not-in $env or ('ATUIN_SHLVL' not-in $env) or ($env.ATUIN_SHLVL != ($env.SHLVL? | default "")) {
- $env.ATUIN_SESSION = (random uuid -v 7 | str replace -a "-" "")
- $env.ATUIN_SHLVL = ($env.SHLVL? | default "")
-}
-hide-env -i ATUIN_HISTORY_ID
-
-def _atuin_osc133_command_executed [] {
- if 'ATUIN_PTY_PROXY_ACTIVE' not-in $env {
- return
- }
- if 'ATUIN_HISTORY_ID' not-in $env or ($env.ATUIN_HISTORY_ID | is-empty) {
- return
- }
-
- print -n $"(char esc)]133;C(char bel)"
-}
-
-def _atuin_osc133_command_finished [exit_code: int] {
- if 'ATUIN_PTY_PROXY_ACTIVE' not-in $env {
- return
- }
- if 'ATUIN_HISTORY_ID' not-in $env or ($env.ATUIN_HISTORY_ID | is-empty) {
- return
- }
-
- print -n $"(char esc)]133;D;($exit_code);history_id=($env.ATUIN_HISTORY_ID);session_id=($env.ATUIN_SESSION)(char bel)"
-}
-
-# Magic token to make sure we don't record commands run by keybindings
-let ATUIN_KEYBINDING_TOKEN = $"# (random uuid)"
-
-let _atuin_pre_execution = {||
- if ($nu | get history-enabled?) == false {
- return
- }
- let cmd = (commandline)
- if ($cmd | is-empty) {
- return
- }
- if not ($cmd | str starts-with $ATUIN_KEYBINDING_TOKEN) {
- $env.ATUIN_HISTORY_ID = (atuin history start -- $cmd | complete | get stdout | str trim)
- _atuin_osc133_command_executed
- }
-}
-
-let _atuin_pre_prompt = {||
- let last_exit = $env.LAST_EXIT_CODE
- if 'ATUIN_HISTORY_ID' not-in $env {
- return
- }
- _atuin_osc133_command_finished $last_exit
- with-env { ATUIN_LOG: error } {
- if (version).minor >= 104 or (version).major > 0 {
- job spawn {
- ^atuin history end $'--exit=($env.LAST_EXIT_CODE)' -- $env.ATUIN_HISTORY_ID | complete
- } | ignore
- } else {
- do { atuin history end $'--exit=($last_exit)' -- $env.ATUIN_HISTORY_ID } | complete
- }
-
- }
- hide-env ATUIN_HISTORY_ID
-}
-
-def _atuin_search_cmd [...flags: string] {
- if (version).minor >= 106 or (version).major > 0 {
- [
- $ATUIN_KEYBINDING_TOKEN,
- ([
- `with-env { ATUIN_LOG: error, ATUIN_QUERY: (commandline), ATUIN_SHELL: nu } {`,
- ([
- 'let output = (run-external atuin search',
- ($flags | append [--interactive] | each {|e| $'"($e)"'}),
- 'e>| str trim)',
- ] | flatten | str join ' '),
- 'if ($output | str starts-with "__atuin_accept__:") {',
- 'commandline edit --accept ($output | str replace "__atuin_accept__:" "")',
- '} else {',
- 'commandline edit $output',
- '}',
- `}`,
- ] | flatten | str join "\n"),
- ]
- } else {
- [
- $ATUIN_KEYBINDING_TOKEN,
- ([
- `with-env { ATUIN_LOG: error, ATUIN_QUERY: (commandline) } {`,
- 'commandline edit',
- '(run-external atuin search',
- ($flags | append [--interactive] | each {|e| $'"($e)"'}),
- ' e>| str trim)',
- `}`,
- ] | flatten | str join ' '),
- ]
- } | str join "\n"
-}
-
-$env.config = ($env | default {} config).config
-$env.config = ($env.config | default {} hooks)
-$env.config = (
- $env.config | upsert hooks (
- $env.config.hooks
- | upsert pre_execution (
- $env.config.hooks | get pre_execution? | default [] | append $_atuin_pre_execution)
- | upsert pre_prompt (
- $env.config.hooks | get pre_prompt? | default [] | append $_atuin_pre_prompt)
- )
-)
-
-$env.config = ($env.config | default [] keybindings)