nnn/plugins/drag-file
0xACE 262c94f696 Check for alternative name for drag/drop exec (#354)
KDE dragon player collides with the name of the drag/drop dependency. On
archlinux the binary is renamed to `dragon-drag-and-drop`.

This change tries `dragon-drag-and-drop` before defaulting to `dragon`.
2019-10-13 00:48:50 +05:30

55 lines
1.1 KiB
Bash
Executable file

#!/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()
{
if which dragon-drag-and-drop; then
dragon-drag-and-drop "$@"
else
dragon "$@"
fi
}
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