69 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
if (not-eq (str:trim-space $line) '') {
12
set-env ATUIN_HISTORY_ID (atuin history start -- $line)
13
}
14
} catch e {
15
unset-env ATUIN_HISTORY_ID
16
}
17
}]
18
19
set edit:after-command = [$@edit:after-command {|m|
20
if (has-env ATUIN_HISTORY_ID) {
21
var exit-status = 0
22
if (not-eq $m[error] $nil) {
23
if (has-key $m[error][reason] exit-status) {
24
set exit-status = $m[error][reason][exit-status]
25
} else {
26
set exit-status = 127
27
}
28
}
29
var duration = (exact-num (math:round (* $m[duration] 1000000000)))
30
31
var history-end = {
32
tmp E:ATUIN_LOG = 'error'
33
atuin history end --exit $exit-status --duration $duration -- $E:ATUIN_HISTORY_ID >$os:dev-null 2>&1
34
unset-env ATUIN_HISTORY_ID
35
}
36
37
if $notify-bg-job-success {
38
$history-end
39
} else {
40
$history-end &
41
}
42
}
43
}]
44
45
fn search {|@argv|
46
var accept-prefix = '__atuin_accept__:'
47
48
var p = (file:pipe)
49
# TODO: Will need an elvish flag in Atuin binary
50
with [E:ATUIN_LOG = 'error'] [E:ATUIN_SHELL_BASH = t] [E:ATUIN_QUERY = $edit:current-command] {
51
atuin search $@argv -i >$os:dev-tty 2>$p; edit:redraw &full=$true
52
}
53
file:close $p[w]
54
var command = (str:trim-space (slurp < $p))
55
file:close $p[r]
56
57
if (not-eq $command '') {
58
if (str:has-prefix $command $accept-prefix) {
59
edit:replace-input (str:trim-prefix $command $accept-prefix)
60
edit:return-line
61
} else {
62
edit:replace-input $command
63
}
64
}
65
}
66
67
fn search-up {
68
search --shell-up-key-binding
69
}
70