Modules for Elvish Shell

Adding atuin.elv

Changed files
+70 -9
+11 -9
README.md
··· 16 16 17 17 ```nix 18 18 { 19 - inputs = { 20 - mellon.url = "github:ejrichards/mellon"; 21 - }; 22 - 23 - outputs = { 24 - mellon, 25 - ... 26 - }: 27 - { 28 19 ... 29 20 nixosConfigurations = { 30 21 modules = [ ··· 38 29 39 30 ```elvish 40 31 use github.com/ejrichards/mellon/<module> 32 + ``` 33 + 34 + ## `atuin.elv` 35 + 36 + Add bindings for `Ctrl-r` and `Up` to use atuin for searching history. 37 + ```elvish 38 + if (has-external atuin) { 39 + use github.com/ejrichards/mellon/atuin 40 + set edit:insert:binding[Ctrl-r] = { atuin:search } 41 + set edit:insert:binding[Up] = { atuin:search-up } 42 + } 41 43 ``` 42 44 43 45 ## `fzf.elv`
+59
atuin.elv
··· 1 + use math 2 + use os 3 + use file 4 + use str 5 + 6 + set-env ATUIN_SESSION (atuin uuid) 7 + unset-env ATUIN_HISTORY_ID 8 + 9 + set edit:after-readline = [$@edit:after-readline {|line| 10 + try { 11 + set-env ATUIN_HISTORY_ID (atuin history start -- $line) 12 + } catch e { 13 + unset-env ATUIN_HISTORY_ID 14 + } 15 + }] 16 + 17 + set edit:after-command = [$@edit:after-command {|m| 18 + if (has-env ATUIN_HISTORY_ID) { 19 + var exit-status = 0 20 + if (not-eq $m[error] $nil) { 21 + if (has-key $m[error][reason] exit-status) { 22 + set exit-status = $m[error][reason][exit-status] 23 + } else { 24 + set exit-status = 127 25 + } 26 + } 27 + var duration = (exact-num (math:round (* $m[duration] 1000000000))) 28 + 29 + with E:ATUIN_LOG = 'error' { atuin history end --exit $exit-status --duration=$duration -- $E:ATUIN_HISTORY_ID >$os:dev-null 2>&1 & } 30 + 31 + unset-env ATUIN_HISTORY_ID 32 + } 33 + }] 34 + 35 + fn search {|@argv| 36 + var accept-prefix = '__atuin_accept__:' 37 + 38 + var p = (file:pipe) 39 + # TODO: Will need an elvish flag in Atuin binary 40 + with [E:ATUIN_LOG = 'error'] [E:ATUIN_SHELL_BASH = t] [E:ATUIN_QUERY = $edit:current-command] { 41 + atuin search $@argv -i >$os:dev-tty 2>$p; edit:redraw &full=$true 42 + } 43 + file:close $p[w] 44 + var command = (str:trim-space (slurp < $p)) 45 + file:close $p[r] 46 + 47 + if (not-eq $command '') { 48 + if (str:has-prefix $command $accept-prefix) { 49 + edit:replace-input (str:trim-prefix $command $accept-prefix) 50 + edit:return-line 51 + } else { 52 + edit:replace-input $command 53 + } 54 + } 55 + } 56 + 57 + fn search-up { 58 + search --shell-up-key-binding 59 + }