Only via a shell loop (xsel
is used in this case):
nnoremap <silent> yf :!for f in %f:p; do if [ -d "$f" ]; then echo "$f/"; else echo "$f"; fi; done | xsel --input --clipboard %i<cr>
Also tried to do this via Lua:
local M = { }
local function append(sel, entry)
local line = entry.location .. "/" .. entry.name
if entry.type == 'dir' then
line = line .. '/'
end
sel[#sel + 1] = line
end
local function yf(info)
local view = vifm.currview()
local selection = { }
for i = 1, view.entrycount do
local entry = view:entry(i)
if entry.selected then
append(selection, entry)
end
end
if #selection == 0 then
local entry = view:entry(view.currententry)
append(selection, entry)
end
local job = vifm.startjob {
cmd = "xsel --clipboard --input",
iomode = "w",
}
local pipe = job:stdin()
pipe:write(table.concat(selection, '\n'))
pipe:close()
if job:exitcode() ~= 0 then
vifm.errordialog("plugin: " .. vifm.plugin.name,
"Failed to copy selection to clipboard")
else
vifm.sb.info(string.format("Yanked paths to %d file(s)", #selection))
end
end
local added = vifm.keys.add {
shortcut = "yf",
modes = { "normal" },
description = "yank selection to clipboard",
handler = yf,
}
if not added then
vifm.sb.error("Failed to register `yf` key")
end
return M