Skip to content

Instantly share code, notes, and snippets.

@voiski
Last active October 2, 2020 20:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save voiski/a473a08eb46a397255cb3fa09bb5c72c to your computer and use it in GitHub Desktop.
Save voiski/a473a08eb46a397255cb3fa09bb5c72c to your computer and use it in GitHub Desktop.
# Add it in your alias
# usage: bash-record final_gif_name speed:optional cast_file:optional
#
# Requires asciinema and docker.
# Optional to have gifsicle for gif optimization.
#
# Examples:
# bash-record testing-command-x
# bash-record slow-recording-x 2
# bash-record please-faster-x 20 /tmp/slow-recording-x.cast
# bash-play /tmp/testing-command-x.cast
function bash-record-asciinema(){ # bash-record-asciinema cast_name no_override:optional
[ -z "$1" ] && echo "Usage: $0 <name>" && return 1
local cast_file="$1"
if [ -f $cast_file ] && [ "$2" != "" ];then
echo "File ${cast_file} already exist!"
return 215
fi
asciinema rec $cast_file -y --overwrite
grep "." $cast_file| tail -2 | grep exit | grep 1001 &> /dev/null && return 1001 || true
}
function bash-play(){ # bash-play cast_name
[ -z "$1" ] && echo "Usage: $0 <name>" && return 1
local cast_file="$1"
asciinema play --idle-time-limit=1 --speed=${2:-5} $cast_file
}
function bash-record(){ # bash-record final_gif_name speed:optional cast_file:optional
[ -z "$1" ] && echo "Usage: $0 <name> speed:optional cast_file:optional" && return 1
local cast_file=${3:-/tmp/$1.cast}
(bash-record-asciinema $cast_file ${3} || [ $? = 215 ]) || return 1
time docker run --rm -v $(dirname $cast_file):/tmp -v $PWD:/data asciinema/asciicast2gif \
-s ${2:-10} \
-S 1 \
$cast_file "./$1.gif"
# https://www.robinstewart.com/blog/2018/10/adding-a-delay-to-the-end-of-an-animated-gif/
if command -v gifsicle &>/dev/null
then gifsicle -U $1.gif "#0--2" -d100 "#-1" -O2 > $1-optimised.gif
fi
}
function bash-record-svg(){ # bash-record final_gif_name speed:optional cast_file:optional
[ -z "$1" ] && echo "Usage: $0 <name> speed:optional cast_file:optional" && return 1
local cast_file=${3:-/tmp/$1.cast}
(bash-record-asciinema $cast_file ${3} || [ $? = 215 ]) || return 1
time docker run --rm -v $(dirname $cast_file):/tmp -v $PWD:/data voiski/svg-term-cli \
--in "/tmp/$1.cast" --out "/data/$1.svg"
# Missing speed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment