From f39d735e2ba625a31a7dbf6fb8bdd62501379ad1 Mon Sep 17 00:00:00 2001 From: zachir Date: Wed, 5 Oct 2022 22:00:32 -0500 Subject: Initial Commit --- xplr/plugins/dragon/src/init.lua | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 xplr/plugins/dragon/src/init.lua (limited to 'xplr/plugins/dragon/src/init.lua') diff --git a/xplr/plugins/dragon/src/init.lua b/xplr/plugins/dragon/src/init.lua new file mode 100644 index 0000000..f0fdc9f --- /dev/null +++ b/xplr/plugins/dragon/src/init.lua @@ -0,0 +1,62 @@ +local function setup(args) + local xplr = xplr + + if args == nil then + args = {} + end + + if args.mode == nil then + args.mode = "selection_ops" + end + + if args.key == nil then + args.key = "D" + end + + if args.keep_selection == nil then + args.keep_selection = false + end + + if args.drag_args == nil then + args.drag_args = "" + end + + if args.drop_args == nil then + args.drop_args = "" + end + + xplr.fn.custom.dragon_drag_n_drop = function(app) + local files = {} + local count = 0 + local cmd = nil + + for i, node in ipairs(app.selection) do + table.insert(files, node.absolute_path) + count = i + end + + if count == 0 then + cmd = "(dragon --target " .. args.drop_args .. " 2> /dev/null | xargs -rl curl -sLO) &\ntrue" + elseif count == 1 then + cmd = "dragon --and-exit " .. args.drag_args .. " '" .. files[1] .. "' > /dev/null 2>&1 &\ntrue" + else + cmd = "dragon " .. args.drag_args .. " '" .. table.concat(files, "' '") .. "' > /dev/null 2>&1 &\ntrue" + end + + os.execute(cmd) + + if not args.keep_selection then + return { "ClearSelection" } + end + end + + xplr.config.modes.builtin[args.mode].key_bindings.on_key[args.key] = { + help = "drag & drop", + messages = { + { CallLuaSilently = "custom.dragon_drag_n_drop" }, + "PopMode", + }, + } +end + +return { setup = setup } -- cgit v1.2.3