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.
 
 
 
 
 
 

66 lignes
1.6 KiB

  1. #!/usr/bin/env sh
  2. # Description: Text based file previewer
  3. #
  4. # Note: This plugin needs a "NNN_FIFO" to work.
  5. #
  6. # Dependencies: tmux (>=3.0) or xterm (or set $TERMINAL), file, tree
  7. #
  8. # Usage:
  9. # You need to set a NNN_FIFO path and set a key for the plugin,
  10. # then start `nnn`:
  11. #
  12. # $ NNN_FIFO=/tmp/nnn.fifo nnn
  13. #
  14. # Then in `nnn`, launch the `preview-tui` plugin.
  15. #
  16. # If you provide the same NNN_FIFO to all nnn instances, there will be a
  17. # single common preview window. I you provide different FIFO path, they
  18. # will be independent.
  19. #
  20. # Shell: POSIX compliant
  21. # Authors: Todd Yamakawa, Léo Villeveygoux
  22. TERMINAL="${TERMINAL:-xterm}"
  23. preview_file () {
  24. clear
  25. lines=$(($(tput lines)-1))
  26. cols=$(tput cols)
  27. encoding="$(file -b --mime-encoding "$1")"
  28. if [ -d "$1" ]; then
  29. # Print directory tree
  30. cd "$1" && tree | head -n $lines | cut -c 1-"$cols"
  31. elif [ "$encoding" = "binary" ] ; then
  32. # Binary file: just print filetype info
  33. echo "-------- Binary file --------"
  34. file -b "$1"
  35. else
  36. # Text file: print file head
  37. head -n $lines "$1" | cut -c 1-"$cols"
  38. fi
  39. }
  40. if [ "$PREVIEW_MODE" ] ; then
  41. if [ ! -r "$NNN_FIFO" ] ; then
  42. echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
  43. read -r
  44. exit 1
  45. fi
  46. preview_file "$1"
  47. exec < "$NNN_FIFO"
  48. while read -r selection ; do
  49. preview_file "$selection"
  50. done
  51. exit 0
  52. fi
  53. if [ -e "${TMUX%%,*}" ] && [ "$(tmux -V | cut -c6)" -eq 3 ] ; then
  54. tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -dh "$0" "$1"
  55. else
  56. PREVIEW_MODE=1 $TERMINAL -e "$0" "$1" &
  57. fi