From aedb9c2753af80fadfa3cf8f5f876473b44531e3 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 2 Nov 2019 06:56:34 +0530 Subject: Update drag and drop plugin --- plugins/README.md | 3 +- plugins/drag-and-drop | 78 --------------------------------------------------- plugins/dragdrop | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 80 deletions(-) delete mode 100755 plugins/drag-and-drop create mode 100755 plugins/dragdrop (limited to 'plugins') diff --git a/plugins/README.md b/plugins/README.md index e68ce25..d3d3b57 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -12,8 +12,7 @@ The currently available plugins are listed below. | boom | sh | [moc](http://moc.daper.net/) | Play random music from dir | | dups | sh | find, md5sum,
sort uniq xargs | List non-empty duplicate files in current dir | | checksum | sh | md5sum,
sha256sum | Create and verify checksums | -| drag-file | sh | [dragon](https://github.com/mwh/dragon) | Drag and drop files from nnn | -| drop-file | sh | [dragon](https://github.com/mwh/dragon) | Drag and drop files into nnn | +| dragdrop | sh | [dragon](https://github.com/mwh/dragon) | Drag/drop files from/into nnn | | fzcd | sh | fzy/fzf
(optional fd) | Change to the directory of a fuzzy-selected file/dir | | fzy-open | sh | fzy, xdg-open | Fuzzy find a file in dir subtree and edit or xdg-open | | getplugs | sh | curl | Update plugins | diff --git a/plugins/drag-and-drop b/plugins/drag-and-drop deleted file mode 100755 index 6db7d5a..0000000 --- a/plugins/drag-and-drop +++ /dev/null @@ -1,78 +0,0 @@ -#!/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. -# -# Files that are dropped will be added to nnn's selection -# Some webbased files will be downloaded to current directory with curl -# and it may overwrite some existing files -# -# The user has to 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 -resp=f -all= - -dnd() -{ - if which dragon-drag-and-drop; then - dragon-drag-and-drop "$@" - else - dragon "$@" - fi -} - -function add_file() { - echo -n "$@" >> "$selection" - echo -ne "\0" >> "$selection" -} - -function use_all() -{ - echo -n "mark --all (a) [default=none]: " - read resp - if [ "$resp" = "a" ]; then - all="--all" - else - all="" - fi -} - -if [ -s "$selection" ]; then - echo -n "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: " - read resp -else - echo -n "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: " - read resp - if [ "$resp" = "s" ]; then - resp=f - fi -fi - -if [ "$resp" = "s" ]; then - use_all - sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 dnd "$all" & -elif [ "$resp" = "d" ]; then - use_all - dnd "$all" "$PWD/"* & -elif [ "$resp" = "r" ]; then - echo -n > "$selection" - 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 & -else - if [ -n "$1" ] && [ -e "$1" ]; then - dnd "$1" & - fi -fi - diff --git a/plugins/dragdrop b/plugins/dragdrop new file mode 100755 index 0000000..6db7d5a --- /dev/null +++ b/plugins/dragdrop @@ -0,0 +1,78 @@ +#!/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. +# +# Files that are dropped will be added to nnn's selection +# Some webbased files will be downloaded to current directory with curl +# and it may overwrite some existing files +# +# The user has to 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 +resp=f +all= + +dnd() +{ + if which dragon-drag-and-drop; then + dragon-drag-and-drop "$@" + else + dragon "$@" + fi +} + +function add_file() { + echo -n "$@" >> "$selection" + echo -ne "\0" >> "$selection" +} + +function use_all() +{ + echo -n "mark --all (a) [default=none]: " + read resp + if [ "$resp" = "a" ]; then + all="--all" + else + all="" + fi +} + +if [ -s "$selection" ]; then + echo -n "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: " + read resp +else + echo -n "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: " + read resp + if [ "$resp" = "s" ]; then + resp=f + fi +fi + +if [ "$resp" = "s" ]; then + use_all + sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 dnd "$all" & +elif [ "$resp" = "d" ]; then + use_all + dnd "$all" "$PWD/"* & +elif [ "$resp" = "r" ]; then + echo -n > "$selection" + 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 & +else + if [ -n "$1" ] && [ -e "$1" ]; then + dnd "$1" & + fi +fi + -- cgit v1.2.3-70-g09d2