-
Notifications
You must be signed in to change notification settings - Fork 0
/
fzf.fnl
176 lines (161 loc) · 5.73 KB
/
fzf.fnl
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
(let
[cmd vim.cmd
commit-format "git log --color --no-merges --pretty=format:'%C(yellow)%h%Creset %s'"
f vim.fn
fzf (require :fzf-lua)
fzf-actions (require :fzf-lua.actions)
fzf-path (require :fzf-lua.path)
git-pager "diffr --colors refine-added:foreground:black --colors refine-removed:foreground:black"
{: delete-buffer-and-file} (require :reflex)
at-home? (fn [] (= (f.getcwd) (fzf-path.HOME)))
cd?
(fn [directory]
(when (at-home?) (cmd (string.format "cd %s" directory))))
path-from-selection (fn [selected] (. (fzf-path.entry_to_file (. selected 1)) :path))
parent (fn [path] (f.fnamemodify path ":h"))
create-file
(fn [path-suggestion] (f.feedkeys (.. ":edit " path-suggestion)))
create-from-selected
(fn [selected] (create-file (path-from-selection selected)))
delete-file
(fn [selected opts]
(delete-buffer-and-file (path-from-selection selected))
(fzf-actions.resume selected opts))
open-file
(fn [selected opts]
(fzf-actions.file_edit_or_qf selected opts)
(cd? (path-from-selection selected)))
open-terminal
(fn [selected]
(let
[path (path-from-selection selected)
directory
(if
(= (f.isdirectory path) 1) path
(parent path))]
; termopen destroys the current buffer and cannot be called from a modified
; one, so before calling it an empty and unchanged one is created
(cmd :enew)
(f.termopen (os.getenv :SHELL) {:cwd directory})
(cd? directory)))
show-directory
(fn [selected] (cmd (string.format "edit %s" (parent (path-from-selection selected)))))]
(fzf.setup
{:actions
{:files
{:default open-file
:ctrl-e create-from-selected
:ctrl-s fzf-actions.file_split
:ctrl-t fzf-actions.file_tabedit
:ctrl-v fzf-actions.file_vsplit
:ctrl-x delete-file
:ctrl-z open-terminal
:ctrl-_ show-directory}}
:buffers ; -3 is needed when using bat as previewer
{:fzf_opts {:--delimiter fzf.utils.nbsp :--with-nth :-3..}
:ignore_current_buffer true}
:diagnostics {:severity_limit :warning}
:defaults
{:copen false
:file_icons :mini
:git_icons false
:header false
:lopen false}
:files {:fzf_opts {:--info :inline}}
:fzf_opts
{:--ansi ""
:--border :none
:--color "bg+:-1,fg+:white" ; Removes the gutter while keeping the text visible
:--cycle ""
:--ellipsis :…
:--info :inline
:--height :100%
:--layout :reverse
:--no-scrollbar ""
:--no-separator ""
:--tabstop :2}
:git
{:bcommits
{:actions {:default fzf-actions.git_checkout}
:cmd (.. commit-format " <file>")
:preview (string.format "git show --color {1} -- {file} | %s" git-pager)}
:commits
{:cmd commit-format
:preview (string.format "git show --color {1} | %s" git-pager)}
:stash
{:actions {:enter fzf-actions.git_stash_pop}
:preview (string.format "git --no-pager stash show --patch {1} | %s" git-pager)}
:status {:actions {:shift-tab [fzf-actions.git_stage_unstage fzf-actions.resume]}}}
:grep
{:path_shorten true
:rg_glob true
:rg_opts "--color always --column --glob !.git --glob !.pijul --hidden --no-heading --smart-case --trim"}
:helptags {:previewer :help_native}
:keymap
{:fzf
{:ctrl-b :preview-page-up
:ctrl-d :half-page-down
:ctrl-f :preview-page-down
:ctrl-u :half-page-up}}
:lsp
{:code_actions {:previewer :codeaction_native}
:trim_entry true}
:previewers
{:bat {:cmd :bat :args "--color always --style plain"}
:codeaction_native {:pager git-pager}
:git_diff
{:cmd_deleted (string.format "git diff HEAD {file} | %s" git-pager)
:cmd_modified (string.format "git diff HEAD {file} | %s" git-pager)}}
:winopts
{:hl
{:border :EndOfBuffer
:preview_border :EndOfBuffer}
:preview
{:border :noborder
:default :bat
:scrollbar false
:title false
:winopts {:number false}}}})
(fzf.register_ui_select)
(let [create-command vim.api.nvim_create_user_command]
(create-command :Branches fzf.git_branches {})
(create-command
:Commits
(fn [args] (if args.bang (fzf.git_bcommits) (fzf.git_commits)))
{:bang true})
(create-command :Stashed fzf.git_stash {})
(create-command :Status fzf.git_status {}))
(let
[with-pijulignore?
(fn [str]
; Both fd and rg rise an error if --ignore-file doesn't exist
; so it must be added conditionally
(if (= (f.filereadable :.pijulignore) 1)
(string.format "%s %s" str "--ignore-file .pijulignore")
str))]
(fn files []
(fzf.files
{:fd_opts
(string.format
"--color never --follow --hidden %s"
(if
; Without the last . fd only finds directories in Documents and Projects
; but not $HOME 🤔
(at-home?) "--exclude .Trash --max-depth 1 . Documents Projects ."
(with-pijulignore? "--exclude *.enc --type f")))}))
(fn grep []
(if
(at-home?) (fzf.grep)
(fzf.live_grep
{:rg_opts (with-pijulignore? "--vimgrep")})))
(let [set-map (fn [lhs rhs] (vim.keymap.set :n lhs rhs))]
(set-map :<leader>b fzf.buffers)
(set-map :<leader>c fzf.command_history)
(set-map :<leader>f files)
(set-map :<leader>g grep)
(set-map :<leader>h fzf.help_tags)
(set-map :<leader>o fzf.oldfiles)
(set-map :<leader>q fzf.quickfix)
(set-map :<leader>/ fzf.grep_curbuf)
(set-map :<leader>* fzf.grep_cword)
(set-map :z= fzf.spell_suggest))))