-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathopen-this.lua
More file actions
29 lines (26 loc) · 817 Bytes
/
Copy pathopen-this.lua
File metadata and controls
29 lines (26 loc) · 817 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
_G.OpenThis = function(fname)
local cmd = 'ot --editor nvim --json ' .. vim.fn.shellescape(fname)
local handle = io.popen(cmd)
local result = handle:read('*a')
handle:close()
local jsonResult = vim.fn.json_decode(result)
if jsonResult.success == true then
local editorArgs = table.concat(jsonResult.editor_args, ' ')
vim.cmd('e ' .. editorArgs)
else
print(
'Error: '
.. jsonResult.error
.. (
jsonResult.details
and 'Details: ' .. jsonResult.details
or ''
)
)
end
-- Add the command to the command history
vim.fn.histadd(
':',
string.format(':lua OpenThis("%s")', vim.fn.escape(fname, '"\\'))
)
end