3 # Description: Open a Drag and drop window, to drop files onto other programs.
4 # Also provides drag and drop window for files.
6 # Dependencies: dragon - https://github.com/mwh/dragon
9 # 1. Files that are dropped will be added to nnn's selection
10 # Some web-based files will be downloaded to current dir
11 # with curl and it may overwrite some existing files
12 # 2. The user has to mm to clear nnn's selection first
14 # Shell: POSIX compliant
17 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
20 if type dragon-drag-and-drop >/dev/null 2>&1; then
21 dnd="dragon-drag-and-drop"
22 elif type dragon-drop >/dev/null 2>&1; then
30 printf '%s\0' "$@" >> "$selection"
35 printf "mark --all (a) [default=none]: "
37 if [ "$resp" = "a" ]; then
44 if [ -s "$selection" ]; then
45 printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: "
48 printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: "
50 if [ "$resp" = "s" ]; then
55 if [ "$resp" = "s" ]; then
57 sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" "$all" &
58 elif [ "$resp" = "d" ]; then
60 "$dnd" "$all" "$PWD/"* &
61 elif [ "$resp" = "r" ]; then
63 "$dnd" --print-path --target | while read -r f
65 if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
67 add_file "$PWD/$(basename "$f")"
68 elif [ -e "$f" ]; then
73 if [ -n "$1" ] && [ -e "$1" ]; then