-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilename.lua
More file actions
29 lines (26 loc) · 757 Bytes
/
filename.lua
File metadata and controls
29 lines (26 loc) · 757 Bytes
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
-- Inserts a filename with a (if possible) relative path
-- from a file select dialog.
local M = {}
-- ## Commands
-- Opens a file select dialog and inserts filename in the buffer.
function M.insert_filename()
local current_dir = (buffer.filename or ''):match('.+[/\\]')
if not current_dir then
current_dir = _HOME
end
filename =
ui.dialog('fileselect',
'--title', "Insert filename",
'--select-multiple',
'--with-directory', current_dir)
if filename then
filename = filename:gsub('\n', '')
filename = filename:gsub(current_dir, '')
if buffer:get_sel_text() == '' then
buffer:add_text(filename)
else
buffer:replace_sel(filename)
end
end
end
return M