59 lines
1.4 kB
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
}
60