My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
1.8 KiB

  1. #!/usr/bin/env sh
  2. # Description: Open a Drag and drop window, to drop files onto other programs.
  3. # Also provides drag and drop window for files.
  4. #
  5. # Dependencies: https://github.com/mwh/dragon
  6. #
  7. # Notes:
  8. # - Files that are dropped will be added to nnn's selection
  9. # Some webbased files will be downloaded to current directory with curl
  10. # and it may overwrite some existing files
  11. # - The user has to mm to clear nnn's selection first
  12. #
  13. # Shell: POSIX compliant
  14. # Author: 0xACE
  15. selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
  16. resp=f
  17. all=
  18. if which dragon-drag-and-drop >/dev/null 2>&1; then
  19. dnd="dragon-drag-and-drop"
  20. else
  21. dnd="dragon"
  22. fi
  23. add_file ()
  24. {
  25. printf '%s\0' "$@" >> "$selection"
  26. }
  27. use_all ()
  28. {
  29. printf "mark --all (a) [default=none]: "
  30. read -r resp
  31. if [ "$resp" = "a" ]; then
  32. all="--all"
  33. else
  34. all=""
  35. fi
  36. }
  37. if [ -s "$selection" ]; then
  38. printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: "
  39. read -r resp
  40. else
  41. printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: "
  42. read -r resp
  43. if [ "$resp" = "s" ]; then
  44. resp=f
  45. fi
  46. fi
  47. if [ "$resp" = "s" ]; then
  48. use_all
  49. sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" "$all" &
  50. elif [ "$resp" = "d" ]; then
  51. use_all
  52. "$dnd" "$all" "$PWD/"* &
  53. elif [ "$resp" = "r" ]; then
  54. true > "$selection"
  55. "$dnd" --print-path --target | while read -r f
  56. do
  57. if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
  58. curl -LJO "$f"
  59. add_file "$PWD/$(basename "$f")"
  60. elif [ -e "$f" ]; then
  61. add_file "$f"
  62. fi
  63. done &
  64. else
  65. if [ -n "$1" ] && [ -e "$1" ]; then
  66. "$dnd" "$1" &
  67. fi
  68. fi