--@action Copy paths as… --@version 1.0.0 --@author TheFile.Ninja --@id copy-paths --@description Copies the paths of the marked items (or the one under the cursor) in the form you need: quoted, for PowerShell, for WSL, as Markdown links. --@tags clipboard, terminal --@requires none local items = pane.active():effective_selection() if #items == 0 then ui.message("Mark something first, or put the cursor on it.", "Copy paths") return end -- Each form: its name, how one item is written, what goes between them. -- shell.quote and shell.to_wsl only write text: nothing is started. local FORMS = { { "One per line", function(f) return f.full_path end, "\n" }, { "Quoted, on one line", function(f) return '"' .. f.full_path .. '"' end, " " }, { "For PowerShell", function(f) return shell.quote(f.full_path, "pwsh") end, ", " }, { "For WSL", function(f) return shell.quote(shell.to_wsl(f.full_path), "wsl") end, " " }, { "Markdown links", function(f) return "[" .. f.name .. "]()" end, "\n" }, { "Names only", function(f) return f.name end, "\n" }, } local names = {} for i, form in ipairs(FORMS) do names[i] = form[1] end local choice = ui.choose(#items == 1 and items[1].name or (#items .. " items"), names, "Copy paths as") if not choice then return end local form, out = FORMS[choice], {} for i, f in ipairs(items) do out[i] = form[2](f) end clipboard.set_text(table.concat(out, form[3])) ui.status("Copied " .. #items .. " path(s): " .. form[1])