diff options
| author | 2019-10-12 04:25:30 +0200 | |
|---|---|---|
| committer | 2019-10-12 07:55:30 +0530 | |
| commit | 3eb0a38c5edf9a60da9fa52b2bec54989f2fdb30 (patch) | |
| tree | 2f263c9836fd38c76821740b6504077da5739b45 /plugins/drag-file | |
| parent | 10188fa9b19c5545cd7fbe6db686ea21fce37715 (diff) | |
| download | nnn-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/drag-file')
| -rwxr-xr-x | plugins/drag-file | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/drag-file b/plugins/drag-file new file mode 100755 index 0000000..c44acf9 --- /dev/null +++ b/plugins/drag-file @@ -0,0 +1,50 @@ +#!/usr/bin/env sh + +# Description: Open a Drag and drop window, to drop files onto other programs +# +# Dependency: https://github.com/mwh/dragon +# Shell: POSIX compliant +# Author: 0xACE + +selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +resp=f +all= + +dnd() +{ + dragon "$@" +} + +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 "work with selection (s), current working directory (d) or current file (f) [default=f]: " + read resp +else + echo -n "work with current working directory (d) or 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/"* & +else + if [ -n "$1" ] && [ -e "$1" ]; then + dnd "$1" & + fi +fi |