52 lines
1.1 kB
1
use str
2
use store
3
4
fn history {|&edit-key='tab' &delete-key='ctrl-d' &down-exit=$true @argv|
5
tmp E:SHELL = 'elvish'
6
7
var fzf-args = [
8
--no-multi
9
--no-sort
10
--read0
11
--print0
12
--info-command="print History"
13
--scheme=history
14
--query=$edit:current-command
15
$@argv
16
]
17
18
if (not-eq $edit-key $nil) {
19
set fzf-args = [$@fzf-args --expect=$edit-key]
20
}
21
if (not-eq $delete-key $nil) {
22
set fzf-args = [$@fzf-args --expect=$delete-key]
23
}
24
if $down-exit {
25
set fzf-args = [$@fzf-args --bind 'down:transform:if (<= $E:FZF_POS 1) { print abort } else { print down }']
26
}
27
28
var key line @ignored = (str:split "\x00" (
29
edit:command-history &dedup &newest-first |
30
each {|cmd| printf "%s %s\x00" $cmd[id] $cmd[cmd] } |
31
try {
32
fzf $@fzf-args | slurp
33
} catch {
34
edit:redraw &full=$true
35
return
36
}
37
))
38
edit:redraw &full=$true
39
40
var id command = (str:split &max=2 ' ' $line)
41
42
if (eq $key $delete-key) {
43
store:del-cmd $id
44
edit:notify 'Deleted '$id
45
} else {
46
edit:replace-input $command
47
48
if (not-eq $key $edit-key) {
49
edit:return-line
50
}
51
}
52
}
53