imgpreview (788B)
1 #!/bin/sh 2 # Cross-platform terminal image preview script. 3 HEIGHT="$2" 4 [ -z "$2" ] && HEIGHT="$(tput lines)" 5 os=$(uname -s | tr '[:upper:]' '[:lower:]') 6 case "$os" in 7 linux*) 8 if command -v catimg 1>/dev/null 2>&1; then 9 catimg -H "$HEIGHT" "$1" 10 elif command -v chafa 1>/dev/null 2>&1; then 11 chafa --fill=block --symbols=block -c 256 -s 80x"$HEIGHT" "$1" 12 else 13 printf "Please install catimg or chafa\n" >&2 && exit 1 14 fi 15 ;; 16 darwin*) 17 case "$1" in 18 *.svg) 19 chafa --fill=block --symbols=block -c 256 -s 80x"$HEIGHT" "$1";; 20 *) 21 catimg -H "$HEIGHT" "$1" 22 ;; 23 esac 24 ;; 25 msys*|cygwin*|mingw*|nt|win*) 26 printf "Windows not supported.\n" 27 ;; 28 *) 29 printf "Operating system %s is unknown.\n" "$os" 30 ;; 31 esac