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