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.
 
 
 
 
 
 

72 lignes
2.1 KiB

  1. #!/usr/bin/env sh
  2. # Description: File previewer for kitty term using NNN_FIFO
  3. #
  4. # Dependencies:
  5. # - kitty (https://sw.kovidgoyal.net/kitty/) with allow_remote_control on
  6. # - file
  7. # - exa (https://github.com/ogham/exa) (fallback: ls)
  8. # - bat (https://github.com/sharkdp/bat) (fallback: cat)
  9. # - mediainfo (fallback: file)
  10. #
  11. # Usage:
  12. # This plugin only works in kitty (https://sw.kovidgoyal.net/kitty/),
  13. # and with kitty's 'allow_remote_control' option turned on.
  14. # You need to set a NNN_FIFO path and set a key for the plugin,
  15. # then start `nnn`:
  16. #
  17. # $ NNN_FIFO=/tmp/nnn.fifo nnn
  18. #
  19. # Then in `nnn`, launch the `preview-kitty` plugin.
  20. #
  21. # If you provide the same NNN_FIFO to all nnn instances, there will be a
  22. # single common preview window. I you provide different FIFO path, they
  23. # will be independent.
  24. #
  25. # Shell: POSIX compliant
  26. # Authors: Léo Villeveygoux
  27. preview_file () {
  28. clear
  29. lines=$(($(tput lines)-1))
  30. cols=$(tput cols)
  31. mime="$(file -b --mime-type "$1")"
  32. if [ -d "$1" ]; then
  33. # Print directory tree
  34. # shellcheck disable=SC2015
  35. cd "$1" && \
  36. COLUMNS=$cols exa -G --colour=always 2>/dev/null || ls --color=alway
  37. elif [ "${mime%%/*}" = "text" ] ; then
  38. # Print file head
  39. bat --terminal-width="$cols" --paging=never --decorations=always \
  40. --color=always "$1" 2>/dev/null || cat
  41. elif [ "${mime%%/*}" = "image" ] ; then
  42. kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$1"
  43. else
  44. # Binary file
  45. printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
  46. mediainfo "$1" 2>/dev/null || file -b "$1"
  47. fi | head -n $lines
  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. kitty @ launch --no-response --title "nnn preview" --keep-focus \
  63. --cwd="$PWD" --env "NNN_FIFO=$NNN_FIFO" --env "PREVIEW_MODE=1" \
  64. "$0" "$1" > /dev/null