64 lines
1.6 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
var history-end = {
30
tmp E:ATUIN_LOG = 'error'
31
atuin history end --exit $exit-status --duration $duration -- $E:ATUIN_HISTORY_ID >$os:dev-null 2>&1
32
unset-env ATUIN_HISTORY_ID
33
}
34
35
# TODO: Add option to not background for use with `$notify-bg-job-success`?
36
$history-end &
37
}
38
}]
39
40
fn search {|@argv|
41
var accept-prefix = '__atuin_accept__:'
42
43
var p = (file:pipe)
44
# TODO: Will need an elvish flag in Atuin binary
45
with [E:ATUIN_LOG = 'error'] [E:ATUIN_SHELL_BASH = t] [E:ATUIN_QUERY = $edit:current-command] {
46
atuin search $@argv -i >$os:dev-tty 2>$p; edit:redraw &full=$true
47
}
48
file:close $p[w]
49
var command = (str:trim-space (slurp < $p))
50
file:close $p[r]
51
52
if (not-eq $command '') {
53
if (str:has-prefix $command $accept-prefix) {
54
edit:replace-input (str:trim-prefix $command $accept-prefix)
55
edit:return-line
56
} else {
57
edit:replace-input $command
58
}
59
}
60
}
61
62
fn search-up {
63
search --shell-up-key-binding
64
}
65