#!/bin/sh -e
#
# for use in vim: `fzf#run({... 'options': '--preview "codepreview {}"'})`

file="$*"
# shellcheck disable=SC2249
case $(file -L -i "${file}") in
  *binary* | *shellscript*)
    (
      highlight --out-format=ansi --line-numbers "${file}" \
        || rougify "${file}" \
        || bat --color=always "${file}"
    ) 2>/dev/null | head -500
    ;;
  *text/plain*)
    (
      bat --color=always "${file}" \
        || cat "${file}"
    ) 2>/dev/null | head -500
    ;;
esac
