diff --git a/bootstrap/packages_stable.tsv b/bootstrap/packages_stable.tsv index b5fa2f2..a35d4e3 100644 --- a/bootstrap/packages_stable.tsv +++ b/bootstrap/packages_stable.tsv @@ -16,6 +16,7 @@ asix-ax88179-dkms A kernel module for ASIX AX88178A AX88179 USB 3.0 network adap aspell-de German dictionary for aspell R aspell-en English dictionary for aspell R atool A script for managing file archives of various types R +atuin Magical shell history R aubio A tool for extracting annotations from audio signals R autofs A kernel-based automounter for Linux A barrier Open-source KVM software based on Synergy (GUI) R diff --git a/terminal/.bashrc b/terminal/.bashrc index ac40475..eac6a0c 100644 --- a/terminal/.bashrc +++ b/terminal/.bashrc @@ -32,3 +32,5 @@ eval "$(zoxide init bash)" set -o vi stty time 0 bind 'set keyseq-timeout 1' + +eval "$(atuin init bash)" diff --git a/terminal/.config/nushell/config.nu b/terminal/.config/nushell/config.nu index 23344a9..4ea3a50 100644 --- a/terminal/.config/nushell/config.nu +++ b/terminal/.config/nushell/config.nu @@ -766,3 +766,4 @@ $env.PROMPT_INDICATOR_VI_NORMAL = "⟨ " $env.PROMPT_MULTILINE_INDICATOR = "::: " use ~/.cache/starship/init.nu +source ~/.local/share/atuin/init.nu diff --git a/terminal/.config/zsh/.zshrc b/terminal/.config/zsh/.zshrc index f4156a8..898652b 100644 --- a/terminal/.config/zsh/.zshrc +++ b/terminal/.config/zsh/.zshrc @@ -94,6 +94,7 @@ setopt autocd eval "$(starship init zsh)" eval "$(zoxide init zsh)" +eval "$(atuin init zsh)" # Speed up autocomplete, force prefix mapping zstyle ':completion:*' accept-exact '*(N)' diff --git a/terminal/.local/share/atuin/init.nu b/terminal/.local/share/atuin/init.nu new file mode 100644 index 0000000..93ebb7f --- /dev/null +++ b/terminal/.local/share/atuin/init.nu @@ -0,0 +1,81 @@ +# Source this in your ~/.config/nushell/config.nu +$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 ($cmd | is-empty) { + return + } + if not ($cmd | str starts-with $ATUIN_KEYBINDING_TOKEN) { + $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 { ATUIN_LOG: error } { + do { atuin history end $'--exit=($last_exit)' -- $env.ATUIN_HISTORY_ID | null } | null + + } + hide-env ATUIN_HISTORY_ID +} + +def _atuin_search_cmd [...flags: string] { + [ + $ATUIN_KEYBINDING_TOKEN, + ([ + `commandline (ATUIN_LOG=error run-external --redirect-stderr atuin search`, + ($flags | append [--interactive, --] | each {|e| $'"($e)"'}), + `(commandline) | complete | $in.stderr | str substring ..-1)`, + ] | 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 -i pre_execution | default [] | append $_atuin_pre_execution) + | upsert pre_prompt ( + $env.config.hooks | get -i pre_prompt | default [] | append $_atuin_pre_prompt) + ) +) + +$env.config = ($env.config | default [] keybindings) + +$env.config = ( + $env.config | upsert keybindings ( + $env.config.keybindings + | append { + name: atuin + modifier: control + keycode: char_r + mode: [emacs, vi_normal, vi_insert] + event: { send: executehostcommand cmd: (_atuin_search_cmd) } + } + ) +) + +# The up arrow keybinding has surprising behavior in Nu, and is disabled by default. +# See https://github.com/atuinsh/atuin/issues/1025 for details +# $env.config = ( +# $env.config | upsert keybindings ( +# $env.config.keybindings +# | append { +# name: atuin +# modifier: none +# keycode: up +# mode: [emacs, vi_normal, vi_insert] +# event: { send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') } +# } +# ) +# ) +