Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.2 KiB

  1. #!/usr/bin/env sh
  2. preview() {
  3. cat <<-EOF | paste -sd '' >"$LF_UEBERZUG_FIFO"
  4. {
  5. "action": "add", "identifier": "lf-preview",
  6. "path": "$1", "x": $4, "y": $5, "width": $2, "height": $3,
  7. "scaler": "contain"
  8. }
  9. EOF
  10. }
  11. set -C -f -u
  12. IFS=$'\n'
  13. lf-ueberzug-cleaner # clean active preview
  14. file="$1"; shift
  15. # Settings
  16. HIGHLIGHT_SIZE_MAX=262143 # 256KiB
  17. HIGHLIGHT_TABWIDTH=8
  18. HIGHLIGHT_STYLE='base16/oceanicnext'
  19. PYGMENTIZE_STYLE='autumn'
  20. case "$(basename "$file" | tr '[A-Z]' '[a-z]')" in
  21. # Archive
  22. *.a|*.ace|*.alz|*.arc|*.arj|*.bz|*.bz2|*.cab|*.cpio|*.deb|*.gz|*.jar|*.lha|*.lz|*.lzh|*.lzma|*.lzo|\
  23. *.rpm|*.rz|*.t7z|*.tar|*.tbz|*.tbz2|*.tgz|*.tlz|*.txz|*.t*.Z|*.tzo|*.war|*.xpi|*.xz|*.Z|*.zip)
  24. atool --list -- "$file"
  25. bsdtar --list --file "$file"
  26. exit 1;;
  27. *.rar)
  28. # Avoid password prompt by providing empty password
  29. unrar lt -p- -- "$file"
  30. exit 1;;
  31. *.7z)
  32. # Avoid password prompt by providing empty password
  33. 7z l -p -- "$file"
  34. exit 1;;
  35. # BitTorrent
  36. *.torrent)
  37. transmission-show -- "$file"
  38. exit 1;;
  39. # OpenDocument
  40. *.odt|*.ods|*.odp|*.sxw)
  41. # Preview as text conversion
  42. odt2txt "$file"
  43. exit 1;;
  44. # HTML
  45. *.htm|*.html|*.xhtml)
  46. # Preview as text conversion
  47. w3m -dump "$file"
  48. lynx -dump -- "$file"
  49. elinks -dump "$file"
  50. exit 1;; # Continue with next handler on failure
  51. *.avi|*.mp4|*.mkv)
  52. thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png"
  53. ffmpegthumbnailer -i "$file" -o "$thumbnail" -s 0
  54. preview "$thumbnail" "$@"
  55. exit 127;;
  56. *.pdf)
  57. thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png"
  58. gs -o "$thumbnail" -sDEVICE=pngalpha -dLastPage=1 "$file" >/dev/null
  59. preview "$thumbnail" "$@"
  60. exit 127;;
  61. *.jpg|*.jpeg|*.png|*.bmp)
  62. preview "$file" "$@"
  63. exit 127;;
  64. *.svg)
  65. thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png"
  66. convert "$file" "$thumbnail"
  67. preview "$thumbnail" "$@"
  68. exit 127;;
  69. esac
  70. MIMETYPE="$( file --dereference --brief --mime-type -- "$file" )"
  71. case "$MIMETYPE" in
  72. # Text
  73. text/plain)
  74. cat "$file"
  75. exit 127;;
  76. text/* | */xml)
  77. # Syntax highlight
  78. if [ "$( stat --printf='%s' -- "$file" )" -gt "$HIGHLIGHT_SIZE_MAX" ]; then
  79. notify-send 123 123123
  80. exit 2
  81. fi
  82. if [ "$( tput colors )" -ge 256 ]; then
  83. pygmentize_format='terminal256'
  84. highlight_format='xterm256'
  85. else
  86. pygmentize_format='terminal'
  87. highlight_format='ansi'
  88. fi
  89. highlight --replace-tabs="$HIGHLIGHT_TABWIDTH" --out-format="$highlight_format" --style="$HIGHLIGHT_STYLE" --force -- "$file"
  90. # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "$file"
  91. exit 127;;
  92. # Image
  93. image/*)
  94. # Preview as text conversion
  95. # img2txt --gamma=0.6 -- "$file" && exit 1
  96. exiftool "$file"
  97. exit 1;;
  98. # Video and audio
  99. video/* | audio/*|application/octet-stream)
  100. mediainfo "$file"
  101. exiftool "$file"
  102. exit 1;;
  103. esac
  104. echo '----- File Type Classification -----' && file --dereference --brief -- "$file"
  105. exit 1