Created
August 27, 2014 14:53
-
-
Save tristanwietsma/b2d0dafa88ebedfa2ca3 to your computer and use it in GitHub Desktop.
Record terminal session to GIF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TIMING=$1 | |
SCRIPT=$2 | |
W=$WINDOWID | |
rm -rf /tmp/script-replay-gifs/ | |
mkdir /tmp/script-replay-gifs/ | |
t=$(mktemp) | |
cp $SCRIPT $t | |
#remove first line | |
sed -i '1d' $t | |
#clear screen | |
clear | |
#read timing file one by one | |
curr=0 | |
i=0 | |
while read line | |
do | |
#capture time and chars to read | |
cols=($line) | |
chars=${cols[1]} | |
#read from current char the number of chars to read | |
dd if=$t bs=1 skip=$curr count=$chars 2>/dev/null | |
#convert to gif frame with a nice frame-number | |
n=$(printf "%010d" $i) | |
import -window $WINDOWID /tmp/script-replay-gifs/$n.gif | |
#and move to next position | |
curr=$((curr+chars)) | |
i=$((i+1)) | |
done <$TIMING | |
rm -f $t | |
#now, set gif with delay per frame | |
i=1 | |
while read line | |
do | |
cols=($line) | |
timing=${cols[0]} | |
#get next image | |
file=$(ls -1 /tmp/script-replay-gifs/ | head -n $i | tail -n 1) | |
timing=$(echo "$timing*100" | bc -l | awk '{print int($0)}') | |
command=$command" -delay $timing /tmp/script-replay-gifs/$file" | |
i=$((i+1)) | |
done < $TIMING | |
convert $command /tmp/anim-notoptim.gif | |
convert /tmp/anim-notoptim.gif -coalesce -layers Optimize /tmp/anim.gif | |
rm -f /tmp/anim-notoptim.gif | |
rm -rf /tmp/script-replay-gifs/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment