#!/usr/bin/env bash has_cmd() { for opt in "$@"; do if command -v "$opt" >/dev/null; then continue else return $? fi done } mime=$(file -Lbs --mime-type "$1") case "$mime" in # https://github.com/wofr06/lesspipe/pull/107 inode/directory) if has_cmd eza; then eza -hl --git --color=always --icons=always "$1" elif has_cmd exa; then exa -hl --color=always --icons "$1" else exit 1 fi ;; # https://github.com/wofr06/lesspipe/pull/117 text/* | application/javascript | inode/x-empty) if has_cmd bat; then bat --color=always "$1" elif has_cmd pygmentize; then pygmentize "$1" | less else exit 1 fi ;; # https://github.com/wofr06/lesspipe/pull/115 application/rfc822) if has_cmd bat; then bat --color=always -lEmail "$1" else exit 1 fi ;; # https://github.com/wofr06/lesspipe/pull/110 application/pdf) if has_cmd pdftotext sed; then pdftotext -q "$1" - | sed "s/\f/$(hr ─)\n/g" else exit 1 fi ;; application/json) if has_cmd jupyter bat && [[ "$1" == *.ipynb ]]; then jupyter nbconvert --to python --stdout "$1" | bat --color=always -plpython elif has_cmd jq; then jq -Cr . "$1" else exit 1 fi ;; # https://github.com/wofr06/lesspipe/pull/106 image/*) if has_cmd chafa; then chafa -f symbols "$1" fi if has_cmd exiftool; then exiftool "$1" | bat --color=always -plyaml else exit 1 fi ;; application/vnd.sqlite3) if has_cmd yes sqlite3 bat; then yes .q | sqlite3 "$1" | bat --color=always -plsql else exit 1 fi ;; application/zip) if has_cmd python && [[ "$1" == *.pth ]]; then python <