Skip to content

Instantly share code, notes, and snippets.

@heptal
Last active December 20, 2015 03:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heptal/6066930 to your computer and use it in GitHub Desktop.
Save heptal/6066930 to your computer and use it in GitHub Desktop.
GIFs? In MY terminal?!

Video

Seems to run stable for hours!

If you can't see your cursor after killing it, run tput cnorm

Sometimes you may see a seq error if you run it multiple times with different resolutions in the same session. Easier to make a new session, or you can change it unset the variables used initially.

# Play a gif in the terminal indefinitely. Specify the file/url and the horizontal resolution
# Requires the amazing ImageMagick. `(brew|apt-get|yum) install imagemagick`
function playgif ()
{
    f=$(convert $1 -resize $2 -coalesce txt:-|sed -E 's/ //g;s/#.+:([0-9]+).+/_\1/g;s/.+://;s/\(//;s/\)//;s/#.*//;s/255/254/g;s/([0-9]+,[0-9]+,[0-9]+),[0-9]+/\1/;s/_/ /'|tr '\n' 'z');
    w=$(echo ${f::3}|sed -E 's/([0-9]+).*/\1/');
    clear;
    tput civis;
    while true; do
        for i in ${f[@]};
        do
            j=($(echo $i|tr 'z' '\n'|sed -E '/^[0-9]*$/d;s/(.+),(.+),(.+)/\1\/42.5*36+\2\/42.5*6+\3\/42.5+16/'|bc));
            for r in $(seq 0 $w $((${#j[@]}-$w)));
            do
                p=($(for c in $(seq 0 $(($w-1)));do echo " ${j[$(($r+$c))]} ";done));
                IFS='%';
                k=$(echo ${p[@]}|sed -E 's/^/\\e[0m\\e[48;5;/;s/\ /m\ \ \\e[0m\\e[48;5;/g;s/$/m\ \ \\e[0m/');
                echo -e $k;
                unset IFS;
            done;
            tput cup 0 0;
        done;
    done
}
@stecman
Copy link

stecman commented Dec 17, 2013

This is genius! I had the same issue as @scarolan; replacing \\e with \\033 fixed it for me.

@scarolan
Copy link

scarolan commented Jan 7, 2014

Confirmed @stecman's solution works. It also seems to only work for me in bash, and not zsh, but that might be because I have a heavily tweaked setup with Oh-My-Zsh, powerline, and a patched font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment