Skip to content

Instantly share code, notes, and snippets.

@mooffie
Created June 12, 2018 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooffie/d8c13c62e3638d916627619c30ab37a7 to your computer and use it in GitHub Desktop.
Save mooffie/d8c13c62e3638d916627619c30ab37a7 to your computer and use it in GitHub Desktop.
mc^2: make <F5> launch your own copy command
--
-- This snippet makes the F5 key launch the external 'cp' command.
--
-- It only does this if the string "mozambique" is somewhere in the
-- folder's path. For all other folders, the builtin F5 will kick in.
--
-- *** See also the 'trash' snippet for a more robust code (it does
-- something similar for F8). ***
--
local function my_own_copy(files, target)
for _, file in ipairs(files) do
mc.execute(("cp -v -i %q %q"):format(file, target))
end
end
ui.Panel.bind('f5', function(pnl)
--
-- You can replace the following silly 'mozambique' line with...
--
-- if pnl.vdir:last().vfs_prefix == 'uzip' then
--
-- ...to operate inside zip archives instead.
--
-- Here's a cute idea: you can instead look for the existence of a file
-- with a special name, say ".acme-project", in the current folder or
-- ancestor folders to trigger this custom F5.
--
if pnl.dir:find 'mozambique' then
local files = pnl.marked or { pnl.current }
if prompts.confirm(T"Copy %d files using my own cool technique?":format(#files)) then
abortive(ui.Panel.other, T"The 'other' panel must display a folder!")
my_own_copy(files, ui.Panel.other.dir)
end
else
return false -- By explicitly returning 'false' we fallback to MC's builtin <f5>.
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment