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.

122 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. exit 2
  80. fi
  81. if [ "$( tput colors )" -ge 256 ]; then
  82. pygmentize_format='terminal256'
  83. highlight_format='xterm256'
  84. else
  85. pygmentize_format='terminal'
  86. highlight_format='ansi'
  87. fi
  88. highlight --replace-tabs="$HIGHLIGHT_TABWIDTH" --out-format="$highlight_format" --style="$HIGHLIGHT_STYLE" --force -- "$file"
  89. # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "$file"
  90. exit 127;;
  91. # Image
  92. image/*)
  93. # Preview as text conversion
  94. # img2txt --gamma=0.6 -- "$file" && exit 1
  95. exiftool "$file"
  96. exit 1;;
  97. # Video and audio
  98. video/* | audio/*|application/octet-stream)
  99. mediainfo "$file"
  100. exiftool "$file"
  101. exit 1;;
  102. esac
  103. echo '----- File Type Classification -----' && file --dereference --brief -- "$file"
  104. exit 1