|
|
|
|
@@ -49,10 +49,16 @@ local function nil_or_tonumber(s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function open_file_pos(line, open_cmd)
|
|
|
|
|
local iter = string.gmatch(line, '[^:]+')
|
|
|
|
|
local iter = line:gmatch('[^:]+')
|
|
|
|
|
local file = iter()
|
|
|
|
|
local line_num = nil_or_tonumber(iter())
|
|
|
|
|
local ln = iter()
|
|
|
|
|
local col = nil_or_tonumber(iter()) or 1
|
|
|
|
|
local i = ln and ln:find(' ')
|
|
|
|
|
if i then
|
|
|
|
|
ln = ln:sub(0, i)
|
|
|
|
|
col = 1
|
|
|
|
|
end
|
|
|
|
|
local line_num = nil_or_tonumber(ln)
|
|
|
|
|
if open_cmd ~= 'e' or vis.win.file ~= file then
|
|
|
|
|
open_file(file, open_cmd)
|
|
|
|
|
end
|
|
|
|
|
@@ -61,10 +67,13 @@ local function open_file_pos(line, open_cmd)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function open_file_current_line(open_cmd)
|
|
|
|
|
local function open_file_current_line(open_cmd, keys)
|
|
|
|
|
local line = vis.win.file.lines[vis.win.selection.line]
|
|
|
|
|
vis:info(line)
|
|
|
|
|
open_file_pos(line)
|
|
|
|
|
if keys then
|
|
|
|
|
vis:feedkeys(keys)
|
|
|
|
|
end
|
|
|
|
|
open_file_pos(line, open_cmd)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function escape_and_quoted(s)
|
|
|
|
|
@@ -84,23 +93,33 @@ end
|
|
|
|
|
|
|
|
|
|
local function fzf_sh(arg)
|
|
|
|
|
action = function(out)
|
|
|
|
|
if (out:find('\n') or #out) == #out then
|
|
|
|
|
open_file_pos(out, vis.win.file.modified and 'o' or 'e')
|
|
|
|
|
else
|
|
|
|
|
vis:message(out)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local home = os.getenv('HOME')
|
|
|
|
|
local path = vis.win.file.path or ''
|
|
|
|
|
local dir = path:match('^.*/') or ''
|
|
|
|
|
local reg = ''
|
|
|
|
|
if reg ~= '"' then
|
|
|
|
|
if vis.register ~= '"' then
|
|
|
|
|
reg = string.gsub(vis.registers[vis.register][1], '%z', '')
|
|
|
|
|
end
|
|
|
|
|
local cmd = home .. '/.config/vis/fzf.sh ' .. escape_and_quoted(arg) .. ' ' .. escape_and_quoted(dir) .. ' ' .. escape_and_quoted(reg)
|
|
|
|
|
local cmd = home ..
|
|
|
|
|
'/.config/vis/fzf.sh ' ..
|
|
|
|
|
escape_and_quoted(arg) .. ' ' .. escape_and_quoted(dir) .. ' ' .. escape_and_quoted(reg)
|
|
|
|
|
cmd_action(cmd, action)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function search(cmd, action)
|
|
|
|
|
if action == nil then
|
|
|
|
|
action = function(out)
|
|
|
|
|
if (out:find('\n') or #s) == #s then
|
|
|
|
|
open_file_pos(out, 'e')
|
|
|
|
|
else
|
|
|
|
|
vis:message(out)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if cmd:match('^fzf ') and vis.register ~= '"' then
|
|
|
|
|
@@ -187,17 +206,27 @@ local ripgrep = 'rg --column --line-number --color=always --smart-case'
|
|
|
|
|
|
|
|
|
|
local function close_prev_win()
|
|
|
|
|
vis:feedkeys('<vis-window-prev>')
|
|
|
|
|
if not vis.win:close() then
|
|
|
|
|
vis:feedkeys('<vis-window-next>')
|
|
|
|
|
if vis.win == win then
|
|
|
|
|
vis:info('Last window')
|
|
|
|
|
elseif not vis.win:close() then
|
|
|
|
|
if vis.win.file.modified then
|
|
|
|
|
vis:info('No write since last change')
|
|
|
|
|
else
|
|
|
|
|
vis:command('q')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function close_next_win()
|
|
|
|
|
vis:feedkeys('<vis-window-next>')
|
|
|
|
|
if not vis.win:close() then
|
|
|
|
|
vis:feedkeys('<vis-window-prev>')
|
|
|
|
|
if vis.win == win then
|
|
|
|
|
vis:info('Last window')
|
|
|
|
|
elseif not vis.win:close() then
|
|
|
|
|
if vis.win.file.modified then
|
|
|
|
|
vis:info('No write since last change')
|
|
|
|
|
else
|
|
|
|
|
vis:command('q')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -266,11 +295,23 @@ vis.events.subscribe(vis.events.INIT, function()
|
|
|
|
|
vis:command('fzfmru')
|
|
|
|
|
end, 'fzf recent')
|
|
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, 'gf', function()
|
|
|
|
|
open_file_current_line('o')
|
|
|
|
|
end, 'open file from current line (with line and col')
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' w', function()
|
|
|
|
|
open_file_current_line('e')
|
|
|
|
|
end, 'open file from current line in current window (with optional line and col)')
|
|
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' cd', function()
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' o', function()
|
|
|
|
|
open_file_current_line('o')
|
|
|
|
|
end, 'open file from current line in new window (with optional line and col)')
|
|
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' k', function()
|
|
|
|
|
open_file_current_line('e', '<vis-window-prev>')
|
|
|
|
|
end, 'open file from current line in above window (with optional line and col)')
|
|
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' j', function()
|
|
|
|
|
open_file_current_line('e', '<vis-window-next>')
|
|
|
|
|
end, 'open file from current line in below window (with optional line and col)')
|
|
|
|
|
|
|
|
|
|
vis:map(vis.modes.NORMAL, ' c', function()
|
|
|
|
|
search('zoxide query -l | fzf', function(path)
|
|
|
|
|
vis:command('cd ' .. path)
|
|
|
|
|
end)
|
|
|
|
|
|