#!/bin/bash
 
# https://iterm2.com/images.html
# https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
# https://github.com/dsanson/termpdf
 
if [[ -t 0 || -p /dev/stdin ]] && [ $# == 1 ] && [ -f "$1" ] ; then
    content_type="$(file --brief --mime "$1")"
    if [[ "$content_type" =~ ^image/ ]] && command -v "imgcat" >/dev/null ; then
        imgcat "$1" && exit
    elif [[ "$content_type" =~ ^application/pdf ]] && command -v "termpdf" >/dev/null ; then
        termpdf "$1" && exit
    fi
fi
 
/bin/cat "$@"