1use str
2use store
3
4fn history {|&exact=$true &edit-key='tab' &delete-key='ctrl-d' &border='rounded' &down-exit=$true|
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 --border=$border
15 --query=$edit:current-command
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 $exact {
25 set fzf-args = [$@fzf-args --exact]
26 }
27 if $down-exit {
28 set fzf-args = [$@fzf-args --bind 'down:transform:if (<= $E:FZF_POS 1) { print abort } else { print down }']
29 }
30
31 var key line @ignored = (str:split "\x00" (
32 edit:command-history &dedup &newest-first |
33 each {|cmd| printf "%s %s\x00" $cmd[id] $cmd[cmd] } |
34 try {
35 fzf $@fzf-args | slurp
36 } catch {
37 edit:redraw &full=$true
38 return
39 }
40 ))
41 edit:redraw &full=$true
42
43 var id command = (str:split &max=2 ' ' $line)
44
45 if (eq $key $delete-key) {
46 store:del-cmd $id
47 edit:notify 'Deleted '$id
48 } else {
49 edit:replace-input $command
50
51 if (not-eq $key $edit-key) {
52 edit:return-line
53 }
54 }
55}