diff options
Diffstat (limited to '.config/nnn/plugins')
-rwxr-xr-x | .config/nnn/plugins/joe_clipper | 7 | ||||
-rwxr-xr-x | .config/nnn/plugins/joe_dragdrop | 47 |
2 files changed, 52 insertions, 2 deletions
diff --git a/.config/nnn/plugins/joe_clipper b/.config/nnn/plugins/joe_clipper index 8c0fa5d..54d8095 100755 --- a/.config/nnn/plugins/joe_clipper +++ b/.config/nnn/plugins/joe_clipper @@ -1,9 +1,12 @@ #!/usr/bin/env perl + use strict; use warnings; use Cwd qw(cwd); +use constant XCLIP => 'xclip -selection clipboard '; + sub close_io { open STDIN, '<', '/dev/null' or die $!; @@ -19,7 +22,7 @@ sub clip_img $pid = fork(); if ($pid == 0) { - system("magick $file png:- | xclip -selection clipboard -t image/png"); + system("magick '$file' png:- | " . XCLIP . "-t image/png"); exec( 'notify-send', '-t', '2000', @@ -38,7 +41,7 @@ sub clip_raw $pid = fork(); if ($pid == 0) { - system( "xclip -selection clipboard $file"); + system( "xclip -selection clipboard '$file'"); exec( 'notify-send', '-t', '2000', 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 |