My build of nnn with minor changes
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dragdrop 1.8 KiB

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if which dragon-drag-and-drop >/dev/null 2>&1; then
  18. dnd="dragon-drag-and-drop"
  19. else
  20. dnd="dragon"
  21. fi
  22. add_file ()
  23. {
  24. printf '%s\0' "$@" >> "$selection"
  25. }
  26. use_all ()
  27. {
  28. printf "mark --all (a) [default=none]: "
  29. read -r resp
  30. if [ "$resp" = "a" ]; then
  31. all="--all"
  32. else
  33. all=""
  34. fi
  35. }
  36. if [ -s "$selection" ]; then
  37. printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: "
  38. read -r resp
  39. else
  40. printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: "
  41. read -r resp
  42. if [ "$resp" = "s" ]; then
  43. resp=f
  44. fi
  45. fi
  46. if [ "$resp" = "s" ]; then
  47. use_all
  48. sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" "$all" &
  49. elif [ "$resp" = "d" ]; then
  50. use_all
  51. "$dnd" "$all" "$PWD/"* &
  52. elif [ "$resp" = "r" ]; then
  53. true > "$selection"
  54. "$dnd" --print-path --target | while read -r f
  55. do
  56. if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then
  57. curl -LJO "$f"
  58. add_file "$PWD/$(basename "$f")"
  59. elif [ -e "$f" ]; then
  60. add_file "$f"
  61. fi
  62. done &
  63. else
  64. if [ -n "$1" ] && [ -e "$1" ]; then
  65. "$dnd" "$1" &
  66. fi
  67. fi