vis: add command fzf-files, use it in shell alias vf

This commit is contained in:
2025-09-27 08:39:54 +02:00
parent a7c7862815
commit 4d979f2600
2 changed files with 11 additions and 13 deletions

View File

@@ -29,5 +29,5 @@ ta() {
}
vf() {
fzf --bind 'enter:become:vis {}' -q "$1"
vis "+fzf-files auto-files '$1'"
}

View File

@@ -91,7 +91,7 @@ local function cmd_action(cmd, action)
end
end
local function fzf_sh(arg)
local function fzf_sh(arg, query)
action = function(out)
if (out:find('\n') or #out) == #out then
open_file_pos(out, vis.win.file.modified and 'o' or 'e')
@@ -102,16 +102,19 @@ local function fzf_sh(arg)
local home = os.getenv('HOME')
local path = vis.win.file.path or ''
local dir = path:match('^.*/') or ''
local reg = ''
if vis.register ~= '"' then
reg = string.gsub(vis.registers[vis.register][1], '%z', '')
if not query and vis.register ~= '"' then
query = 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)
escape_and_quoted(arg) .. ' ' .. escape_and_quoted(dir) .. ' ' .. escape_and_quoted(query or '')
cmd_action(cmd, action)
end
vis:command_register('fzf-files', function(argv, force, win, selection, range)
fzf_sh(argv[1] or 'auto-files', argv[2])
end)
local function search(cmd, action)
if action == nil then
action = function(out)
@@ -269,13 +272,8 @@ vis.events.subscribe(vis.events.INIT, function()
'open file slot ' .. num)
end
vis:map(vis.modes.NORMAL, ' s', function()
fzf_sh('auto-search')
end, 'fzf: search')
vis:map(vis.modes.NORMAL, ' f', function()
fzf_sh('auto-files')
end, 'fzf: files')
vis:map(vis.modes.NORMAL, ' s', ':fzf-files auto-search<Enter>', 'fzf: search')
vis:map(vis.modes.NORMAL, ' f', ':fzf-files auto-files<Enter>', 'fzf: files')
vis:map(vis.modes.NORMAL, ' /', function()
search(fzf_reload(ripgrep .. ' --with-filename {q} ' .. escape_and_quoted(vis.win.file.path)))