diff options
Diffstat (limited to 'xplr/plugins/dragon/src')
-rw-r--r-- | xplr/plugins/dragon/src/init.lua | 62 |
1 files changed, 62 insertions, 0 deletions
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 } |