blob: 2623c473a69348f061b21ae339f7dce0c8d65968 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
|