aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/drop-file
diff options
context:
space:
mode:
authorGravatar 0xACE <0xACE@users.noreply.github.com>2019-10-12 04:25:30 +0200
committerGravatar Mischievous Meerkat <engineerarun@gmail.com>2019-10-12 07:55:30 +0530
commit3eb0a38c5edf9a60da9fa52b2bec54989f2fdb30 (patch)
tree2f263c9836fd38c76821740b6504077da5739b45 /plugins/drop-file
parent10188fa9b19c5545cd7fbe6db686ea21fce37715 (diff)
downloadnnn-3eb0a38c5edf9a60da9fa52b2bec54989f2fdb30.tar.gz
Added 2 plugins for drag and drop support (#352)
* Added 2 plugins for drag and drop support These scripts uses https://github.com/mwh/dragon and curl. It allows nnn to drag and drop files either to other programs, or to itself. * added link to dependency and spelling * added drag/drop-file scripts to readme table
Diffstat (limited to 'plugins/drop-file')
-rwxr-xr-xplugins/drop-file40
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/drop-file b/plugins/drop-file
new file mode 100755
index 0000000..d824c30
--- /dev/null
+++ b/plugins/drop-file
@@ -0,0 +1,40 @@
+#!/usr/bin/env sh
+
+# Description: Provides drag and drop window for files.
+#
+# Files that are dropped will be added to nnn's selection
+# Some web based files will be downloaded to current directory with curl
+# and it may overwrite some existing files
+#
+# The user has to press mm to clear nnn's selection first
+#
+# Dependency: https://github.com/mwh/dragon
+# Shell: POSIX compliant
+# Author: 0xACE
+
+selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
+
+dnd()
+{
+ dragon "$@"
+}
+
+function add_file() {
+ echo -n "$@" >> "$selection"
+ echo -ne "\0" >> "$selection"
+}
+
+echo -n > "$selection"
+
+# which dnd
+# upstream calls it dragon
+
+dnd --print-path --target | while read f
+do
+ if echo -n "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
+ curl -LJO "$f"
+ add_file "$PWD/$(basename "$f")"
+ elif [ -e "$f" ]; then
+ add_file "$f"
+ fi
+done &