#!/bin/sh

path=$1

if [ -z "$path" ]; then
	path="."
fi

if [ -d "$path" ]; then
	ls -lha --color=tty "$path"
else
	if [ ! -f "$path" ]; then
		echo "No such file: $path"
		exit 0
	fi

	format="$(file -i "$path" | cut -d' ' -f2)"
	format="${format%%/*}"

	case "$format" in
		"image")
			kitty +kitten icat "$path"
			;;

		*)
			cat "$path"
			;;
	esac
fi
