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.
 
 
 
 
 
 

59 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. # How to use:
  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. # Authors: Todd Yamakawa and Léo Villeveygoux
  21. TERMINAL="${TERMINAL:-xterm}"
  22. if [ "$PREVIEW_MODE" ] ; then
  23. if [ ! -r "$NNN_FIFO" ] ; then
  24. echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
  25. read -r
  26. exit 1
  27. fi
  28. exec < "$NNN_FIFO"
  29. while read -r selection ; do
  30. clear
  31. lines=$(($(tput lines)-1))
  32. cols=$(tput cols)
  33. mime="$(file -b --mime-type "$selection")"
  34. if [ -d "$selection" ]; then
  35. # Print directory tree
  36. cd "$selection" && tree | head -n $lines | cut -c 1-"$cols"
  37. elif [ "${mime%%/*}" = "text" ] ; then
  38. # Print file head
  39. head -n $lines "$selection" | cut -c 1-"$cols"
  40. else
  41. # Binary file
  42. echo "-------- Binary file --------"
  43. file -b "$selection"
  44. fi
  45. done
  46. exit 0
  47. fi
  48. if [ -e "${TMUX%%,*}" ] && [ "$(tmux -V | cut -c6)" -eq 3 ] ; then
  49. tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -dh "$0"
  50. else
  51. PREVIEW_MODE=1 $TERMINAL -e "$0" &
  52. fi