My build of nnn with minor changes
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

57 wiersze
1.7 KiB

  1. #!/usr/bin/env sh
  2. # Description: Show diff of 2 directories or multiple files in vimdiff
  3. #
  4. # Note: 1. vim may show the warning: 'Vim: Warning: Input is not from a terminal'
  5. # press 'Enter' to ignore and proceed.
  6. # 2. if only one file is in selection, the hovered file is considered as the
  7. # second file to diff with
  8. #
  9. # Shell: POSIX compliant
  10. # Authors: Arun Prakash Jana, ath3
  11. selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
  12. if which nvim >/dev/null 2>&1; then
  13. diffcmd="nvim -d"
  14. else
  15. diffcmd="vimdiff +0"
  16. fi
  17. dirdiff() {
  18. dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$1")".XXXXXXXX)
  19. dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$2")".XXXXXXXX)
  20. ls -A1 "$1" > "$dir1"
  21. ls -A1 "$2" > "$dir2"
  22. $diffcmd "$dir1" "$dir2"
  23. rm "$dir1" "$dir2"
  24. }
  25. if [ -s "$selection" ]; then
  26. arr=$(tr '\0' '\n' < "$selection")
  27. if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
  28. f1="$(echo "$arr" | sed -n '1p')"
  29. f2="$(echo "$arr" | sed -n '2p')"
  30. if [ -d "$f1" ] && [ -d "$f2" ]; then
  31. dirdiff "$f1" "$f2"
  32. else
  33. # If xargs supports the -o option, use it to get rid of:
  34. # Vim: Warning: Input is not from a terminal
  35. # xargs -0 -o vimdiff < $selection
  36. eval xargs -0 "$diffcmd" < "$selection"
  37. fi
  38. elif [ -n "$1" ]; then
  39. f1="$(echo "$arr" | sed -n '1p')"
  40. if [ -d "$f1" ] && [ -d "$1" ]; then
  41. dirdiff "$f1" "$1"
  42. elif [ -f "$f1" ] && [ -f "$1" ]; then
  43. $diffcmd "$f1" "$1"
  44. else
  45. echo "cannot compare file with directory"
  46. fi
  47. else
  48. echo "needs at least 2 files or directories selected for comparison"
  49. fi
  50. fi