My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

51 lignes
1.6 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=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
  12. dirdiff() {
  13. dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$1")".XXXXXXXX)
  14. dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$2")".XXXXXXXX)
  15. ls -A1 "$1" > "$dir1"
  16. ls -A1 "$2" > "$dir2"
  17. vimdiff "$dir1" "$dir2"
  18. rm "$dir1" "$dir2"
  19. }
  20. if [ -s "$selection" ]; then
  21. arr=$(tr '\0' '\n' < "$selection")
  22. if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
  23. f1="$(echo "$arr" | sed -n '1p')"
  24. f2="$(echo "$arr" | sed -n '2p')"
  25. if [ -d "$f1" ] && [ -d "$f2" ]; then
  26. dirdiff "$f1" "$f2"
  27. else
  28. # If xargs supports the -o option, use it to get rid of:
  29. # Vim: Warning: Input is not from a terminal
  30. # xargs -0 -o vimdiff < $selection
  31. xargs -0 vimdiff +0 < "$selection"
  32. fi
  33. elif ! [ -z "$1" ]; then
  34. f1="$(echo "$arr" | sed -n '1p')"
  35. if [ -d "$f1" ] && [ -d "$1" ]; then
  36. dirdiff "$f1" "$1"
  37. elif [ -f "$f1" ] && [ -f "$1" ]; then
  38. vimdiff +0 "$f1" "$1"
  39. else
  40. echo "cannot compare file with directory"
  41. fi
  42. else
  43. echo "needs at least 2 files or directories selected for comparison"
  44. fi
  45. fi