From c54b5ef0f166a6454522686e6a2a5c1550505eb0 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 20 Jun 2021 16:50:57 +0200 Subject: update --- bin/icat | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'bin/icat') diff --git a/bin/icat b/bin/icat index 702d648..d363e09 100755 --- a/bin/icat +++ b/bin/icat @@ -1,10 +1,12 @@ #!/bin/sh -e # Display images directly in terminal. -# Tested with xterm v361 +# Tested with xterm v361. Depends on imagemagick convert(1). + +[ "$LC_TERMINAL" = iTerm2 ] && [ -x "$HOME/.iterm2/imgcat" ] && exec "$HOME/.iterm2/imgcat" "$@" # maxsize prints the geomtry size of terminal window, with # a maximum value of 1000 pixels for width and height, or -# 640x480 if size can not be probed. +# 640x480 if terminal size can not be probed. maxsize() { [ "$WINDOWID" ] || { echo "640x480>"; return; } xwininfo -id "$WINDOWID" | { @@ -19,10 +21,42 @@ maxsize() { } } +clearline() { printf "\r \r"; } + +ms=$(maxsize) + # Use convert(1) from imagemagick to output sixel format. # -flatten uses the terminal background color as transparent layer # -resize use the terminal size as bounding box, with a limit of 1000 pixels # image is not resized if smaller than limit #exec convert -resize "$(maxsize)>" -transparent-color white -flatten -- ${1:--} sixel:- # color #rrrrggggbbbb -exec convert -resize "$(maxsize)>" -- ${1:--} sixel:${2:--} +#exec convert -resize "$(maxsize)>" -- ${1:--} sixel:${2:--} + +put=: +while getopts :cpv opt; do + case $opt in + (c) clear=1 ;; + (p) pause=1 put=printf ;; + (v) put=printf ;; + (*) echo "Usage: icat [-cpv] [image_file ...]"; exit 1 ;; + esac +done +shift $((OPTIND - 1)) + +[ "$#" = 0 -o "$#" = 1 -a "$1" = - ] && { + convert -resize "$ms>" - sixel:- + exit +} + +for f; do + $put "Next: %s" "$f" + [ "$pause" ] && { + read -sr + [ "$REPLY" = s ] && clearline && continue + } + [ "$clear" ] && clear + clearline + $put "%s\n" "$f" + convert -resize "$ms>" -- "$f" sixel:- +done -- cgit v1.2.3