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.
 
 
 
 
 
 

69 lignes
1.7 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 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. NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
  23. if [ ! -r "$NNN_FIFO" ] ; then
  24. echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
  25. exit 1
  26. fi
  27. if [ ! -x "$NUKE" ] ; then
  28. echo "Nuke not found!" >&2
  29. exit 1
  30. fi
  31. if [ "$PREVIEW_MODE" ] ; then
  32. exec < "$NNN_FIFO"
  33. while read -r selection ; do
  34. clear
  35. lines=$(($(tput lines)-1))
  36. cols=$(tput cols)
  37. mime="$(file -b --mime-type "$selection")"
  38. if [ "$mime" = "inode/directory" ] ; then
  39. # Print directory tree
  40. cd "$selection" && tree | head -n $lines | cut -c 1-"$cols"
  41. elif [ "${mime%%/*}" = "text" ] ; then
  42. # Print file head
  43. head -n $lines "$selection" | cut -c 1-"$cols"
  44. else
  45. # Binary file
  46. echo "-------- Binary file --------"
  47. file -b "$selection"
  48. fi
  49. done
  50. if [ -e "${TMUX%%,*}" ] ; then
  51. tmux kill-pane
  52. fi
  53. exit 0
  54. fi
  55. if [ -e "${TMUX%%,*}" ] ; then
  56. tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -dh "$0"
  57. else
  58. PREVIEW_MODE=1 GUI=0 $TERMINAL -e "$0" &
  59. fi