My build of nnn with minor changes
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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