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.

preview-tui 1.8 KiB

il y a 4 ans
il y a 4 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 $TERMINAL, less or $PAGER, 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. PAGER="${PAGER:-less}"
  24. preview_file () {
  25. kill "$(jobs -p)" 2>/dev/null
  26. clear
  27. encoding="$(file -b --mime-encoding "$1")"
  28. if [ -d "$1" ]; then
  29. # Print directory tree
  30. cd "$1" || return
  31. # we use a FIFO to access less PID
  32. tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
  33. mkfifo "$tmpfifopath" || return
  34. $PAGER < "$tmpfifopath" &
  35. (
  36. exec > "$tmpfifopath"
  37. tree&
  38. )
  39. rm "$tmpfifopath"
  40. elif [ "$encoding" = "binary" ] ; then
  41. # Binary file: just print filetype info
  42. echo "-------- Binary file --------"
  43. file -b "$1"
  44. else
  45. # Text file:
  46. $PAGER "$1" &
  47. fi
  48. }
  49. if [ "$PREVIEW_MODE" ] ; then
  50. if [ ! -r "$NNN_FIFO" ] ; then
  51. echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
  52. read -r
  53. exit 1
  54. fi
  55. preview_file "$1"
  56. exec < "$NNN_FIFO"
  57. while read -r selection ; do
  58. preview_file "$selection"
  59. done
  60. exit 0
  61. fi
  62. if [ -e "${TMUX%%,*}" ] && [ "$(tmux -V | cut -c6)" -eq 3 ] ; then
  63. tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -dh "$0" "$1"
  64. else
  65. PREVIEW_MODE=1 $TERMINAL -e "$0" "$1" &
  66. fi