Created
December 7, 2018 17:50
-
-
Save alban/ba8c5f1866ef78af0d31b509ab50224b to your computer and use it in GitHub Desktop.
asciinema-normalize.sh
This file contains 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 | |
COUNTER=0.00 | |
OLDCMDLINE=0 | |
NEWCMDLINE=0 | |
while read -r LINE ; do | |
if [[ ! $LINE =~ ^\[ ]]; then | |
#echo "$LINE" | |
echo '{"version": 2, "width": 80, "height": 25, "timestamp": 1600000000, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}' | |
continue | |
fi | |
if [[ $LINE =~ '"exit\r\n"' ]]; then | |
continue | |
fi | |
if [[ $LINE =~ "$(whoami)@$(hostname)" ]]; then | |
NEWCMDLINE=1 | |
else | |
NEWCMDLINE=0 | |
fi | |
if [[ $OLDCMDLINE == "1" ]]; then | |
COUNTER=$(printf '%.2f' "$(bc <<<"scale=2;$COUNTER+1")") | |
elif [[ $LINE =~ '"\r\n"' ]]; then | |
COUNTER=$(printf '%.2f' "$(bc <<<"scale=2;$COUNTER+1")") | |
else | |
COUNTER=$(printf '%.2f' "$(bc <<<"scale=2;$COUNTER+0.05")") | |
fi | |
echo "$LINE" | sed "s/^\[\([0-9\.]*\),/[$COUNTER,/" | |
OLDCMDLINE=$NEWCMDLINE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment