summaryrefslogtreecommitdiffstats
path: root/.config/nnn/plugins/joe_dragdrop
diff options
context:
space:
mode:
Diffstat (limited to '.config/nnn/plugins/joe_dragdrop')
-rwxr-xr-x.config/nnn/plugins/joe_dragdrop47
1 files changed, 47 insertions, 0 deletions
diff --git a/.config/nnn/plugins/joe_dragdrop b/.config/nnn/plugins/joe_dragdrop
new file mode 100755
index 0000000..2623c47
--- /dev/null
+++ b/.config/nnn/plugins/joe_dragdrop
@@ -0,0 +1,47 @@
+#!/usr/bin/env sh
+
+# Description: Open a Drag and drop window, to drop files onto other programs.
+# Also provides drag and drop window for files.
+#
+# Dependencies: dragon - https://github.com/mwh/dragon
+#
+# Notes:
+# 1. Files that are dropped will be added to nnn's selection
+# Some web-based files will be downloaded to current dir
+# with curl and it may overwrite some existing files
+# 2. The user has to mm to clear nnn's selection first
+#
+# Shell: POSIX compliant
+# Author: 0xACE
+
+selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+resp=f
+all=
+if type dragon-drag-and-drop >/dev/null 2>&1; then
+ dnd="dragon-drag-and-drop"
+elif type dragon-drop >/dev/null 2>&1; then
+ dnd="dragon-drop"
+else
+ dnd="dragon"
+fi
+
+add_file ()
+{
+ printf '%s\0' "$@" >> "$selection"
+}
+
+if [ -s "$selection" ]; then
+ printf "Drag selection (s) or drag current file (f) [default=f]: "
+ read -r resp
+else
+ resp=f
+fi
+
+if [ "$resp" = "s" ]; then
+ all="--all"
+ sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" --and-exit "$all" &
+else
+ if [ -n "$1" ] && [ -e "$1" ]; then
+ "$dnd" --and-exit "$1" &
+ fi
+fi