vis: add key for fzf change directory
This commit is contained in:
@@ -70,7 +70,12 @@ local function escape_and_quoted(s)
|
|||||||
return "'" .. s:gsub("'", "\\'") .. "'"
|
return "'" .. s:gsub("'", "\\'") .. "'"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function search(cmd)
|
local function search(cmd, action)
|
||||||
|
if action == nil then
|
||||||
|
action = function(out)
|
||||||
|
open_file_pos(out, 'e')
|
||||||
|
end
|
||||||
|
end
|
||||||
if cmd:match('^fzf ') and vis.register ~= '"' then
|
if cmd:match('^fzf ') and vis.register ~= '"' then
|
||||||
local reg = string.gsub(vis.registers[vis.register][1], '%z', '')
|
local reg = string.gsub(vis.registers[vis.register][1], '%z', '')
|
||||||
if reg ~= '' then
|
if reg ~= '' then
|
||||||
@@ -79,7 +84,7 @@ local function search(cmd)
|
|||||||
end
|
end
|
||||||
local code, out, err = vis:pipe(cmd, true)
|
local code, out, err = vis:pipe(cmd, true)
|
||||||
if code == 0 then
|
if code == 0 then
|
||||||
open_file_pos(out, 'e')
|
action(out)
|
||||||
elseif err ~= nil then
|
elseif err ~= nil then
|
||||||
vis:info(err)
|
vis:info(err)
|
||||||
elseif code ~= 0 then
|
elseif code ~= 0 then
|
||||||
@@ -197,6 +202,12 @@ vis.events.subscribe(vis.events.INIT, function()
|
|||||||
vis:map(vis.modes.NORMAL, 'gf', function()
|
vis:map(vis.modes.NORMAL, 'gf', function()
|
||||||
open_file_current_line('o')
|
open_file_current_line('o')
|
||||||
end, 'open file from current line (with line and col')
|
end, 'open file from current line (with line and col')
|
||||||
|
|
||||||
|
vis:map(vis.modes.NORMAL, ' cd', function()
|
||||||
|
search('zoxide query -l | fzf', function(path)
|
||||||
|
vis:command('cd ' .. path)
|
||||||
|
end)
|
||||||
|
end, 'fzf change directory')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
||||||
|
|||||||
Reference in New Issue
Block a user