dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

preview (1927B)


      1 #!/bin/sh
      2 if command -v bat >/dev/null 2>&1; then
      3   { [ -f ~/.config/dark-theme ] && theme=1337; } || theme=GitHub
      4   pagercmd="bat --color=always --theme=$theme"
      5 else
      6   pagercmd="less -FRiX"
      7 fi
      8 
      9 case "$(printf "%s" "$1" | tr '[:upper:]' '[:lower:]')" in
     10   *.pickle) python -mpickle "$1";;
     11   *.tgz|*.tar.gz) tar tzf "$1";;
     12   *.tar.bz2|*.tbz2) tar tjf "$1";;
     13   *.tar.txz|*.txz) xz --list "$1";;
     14   *.deb) dpkg -c "$1";;
     15   *.tar) tar tf "$1";;
     16   *.zip|*.jar|*.war|*.ear|*.oxt|*.apkg|*.apk) unzip -l "$1";;
     17   *.rar) unrar l "$1";;
     18   *.7z) 7z l "$1";;
     19   *.[1-8]) man "$1" | col -b ;;
     20   *.o) objdump -d "$1" ;; #nm "$1" | less ;;
     21   # *.torrent) transmission-show "$1";;
     22   # *.iso) iso-info --no-header -l "$1";;
     23   *.epub|*.rtf|*.doc|*.docx|*.otd|*.ods|*.odp|*.sxw)
     24     pandoc -s -t markdown -- "$1" | $pagercmd
     25     exit 1
     26     ;;
     27   *.json)
     28     if command -v jq >/dev/null; then
     29       if command -v bat >/dev/null; then jq < "$1" | $pagercmd --file-name "$1"
     30       else jq < "$1" | $pagercmd; fi
     31     else $pagercmd "$1"; fi
     32     ;;
     33   *.csv) sed s/,/\\n/g "$1";;
     34   *.pdf)
     35     CACHE=$(mktemp)
     36     pdftoppm -png -f 1 -singlefile "$1" "$CACHE"
     37     imgpreview "$CACHE.png"
     38     rm "$CACHE"
     39     ;;
     40   *.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.gif|*.svg)
     41     imgpreview "$1"
     42     ;;
     43   *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx])
     44     exiftool "$1"
     45     ;;
     46   *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx)
     47     CACHE=$(mktemp)
     48     ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
     49     imgpreview "$CACHE"
     50     rm "$CACHE"
     51     ;;
     52   *.db)
     53     case $(file --mime-type "$1" -bL) in
     54       application/x-sqlite3) command -v sqlite3 >/dev/null && sqlite3 "$1" '.schema';;
     55       *) ;;
     56     esac
     57     ;;
     58   *)
     59     case $(file --mime-type "$1" -bL) in
     60       application/x-executable) readelf -h "$1" ;;
     61       *)
     62         $pagercmd "$1"
     63         ;;
     64     esac
     65     ;;
     66 esac
     67