Record your bash shell and upload as a gif file

Recording a video when you are typing is all but a waste of resources so I set out on a quest to find the easiest way to record my bash and convert that recording to a gif file that can be posted on wordpress without having to ‘upgrade’ to upload your ‘video’

I came across several solutions
ttystudio
ttygif
seq2gif

but only one offered me a hassle-free experience was asciinema.
The recordings can be made locally or put online instantly. To convert to a gif file you can use asciinema2gif to generate one and you are done with it.
Now you have your recording as a gif.

the asciinema project
the assciinema2gif project

to record a file you type
asciinema rec [filename]
The recording finishes whet typing exit or pressing ctrl+d.
Use a filename if you want to store it locally

Available options:

  • -c, --command= – Specify command to record, defaults to $SHELL
  • -t, --title= – Specify the title of the asciicast
  • -w, --max-wait= – Reduce recorded terminal inactivity to max seconds
  • -y, --yes – Answer “yes” to all prompts (e.g. upload confirmation)
  • -q, --quiet – Be quiet, suppress all notices/warnings (implies -y)
patrick@debian:~/utils$ mkdir ~/utils;cd ~/utils
patrick@debian:~/utils$ git clone --recursive https://github.com/asciinema/asciicast2gif.git
Cloning into 'asciicast2gif'...
remote: Counting objects: 296, done.
remote: Compressing objects: 100% (153/153), done.
remote: Total 296 (delta 145), reused 269 (delta 118), pack-reused 0
Receiving objects: 100% (296/296), 65.03 KiB | 0 bytes/s, done.
Resolving deltas: 100% (145/145), done.
Submodule 'asciinema-player' (https://github.com/asciinema/asciinema-player.git) registered for path 'asciinema-player'
Cloning into '/home/patrick/utils/asciicast2gif/asciinema-player'...
remote: Counting objects: 4425, done.
remote: Total 4425 (delta 0), reused 0 (delta 0), pack-reused 4425
Receiving objects: 100% (4425/4425), 1.56 MiB | 1016.00 KiB/s, done.
Resolving deltas: 100% (2144/2144), done.
Submodule path 'asciinema-player': checked out 'f487580ca161a52bb34613d39e1b27df4ae1642a'
patrick@debian:~/utils$ ls
asciicast2gif

patrick@debian:~/utils$ git clone https://github.com/asciinema/asciinema.git
Cloning into 'asciinema'...
remote: Counting objects: 2682, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 2682 (delta 0), reused 0 (delta 0), pack-reused 2679
Receiving objects: 100% (2682/2682), 1.57 MiB | 936.00 KiB/s, done.
Resolving deltas: 100% (1341/1341), done.
patrick@debian:~/utils$ cd asciinema/
patrick@debian:~/utils/asciinema$ ls
asciinema CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md doc Dockerfile LICENSE Makefile man README.md setup.cfg setup.py tests Vagrantfile
patrick@debian:~/utils/asciinema$ python3 -m asciinema --version
asciinema 1.4.0
patrick@debian:~/utils/asciinema$ git pull
Already up-to-date.
patrick@debian:~/utils/asciinema$ cd ../asciicast2gif/;git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
patrick@debian:~/utils/asciicast2gif$

To be sure you have the latest version don’t forget to git pull in the asciinema directory.

To launch asciinema with python 3 you need to have the path in your pythonpath environment variable at startup so edit your bashrc script and put in the export bit

patrick@debian:~/casts$ echo $PYTHONPATH
patrick@debian:~/casts$ export PYTHONPATH=$PYTHONPATH:~/utils/:~/utils/asciinema/
patrick@debian:~/casts$ echo $PYTHONPATH
:/home/patrick/utils/:/home/patrick/utils/asciinema/

For fun I recorded this with asciinema here asciinema recording

And for more fun I converted it to a gif file for yours truly with asciicast2gif

click on it to view properly

asciinema_create

I also recorded how to install docker and run asciicast2gif. Enjoy my tinkering
Creating a Gif file from you asciinema recording

patrick@debian:~/utils/asciicast2gif$ cd ../../casts/;wget https://asciinema.org/a/e46k1qs5dqgru7mwfygvj969c.json
--2017-05-16 19:46:35-- https://asciinema.org/a/e46k1qs5dqgru7mwfygvj969c.json
Resolving asciinema.org (asciinema.org)... 109.107.38.78
Connecting to asciinema.org (asciinema.org)|109.107.38.78|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://s3-eu-west-1.amazonaws.com/asciinema-bb-eu/uploads/asciicast/file/120837/asciicast.json?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI2DOCAQ34YNJM3GA%2F20170516%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20170516T174635Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=89ffdb5c583822b47c500336077a1897baf63263819cb1790b4cbb7ed1396248 [following]
--2017-05-16 19:46:35-- https://s3-eu-west-1.amazonaws.com/asciinema-bb-eu/uploads/asciicast/file/120837/asciicast.json?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI2DOCAQ34YNJM3GA%2F20170516%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20170516T174635Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=89ffdb5c583822b47c500336077a1897baf63263819cb1790b4cbb7ed1396248
Resolving s3-eu-west-1.amazonaws.com (s3-eu-west-1.amazonaws.com)... 54.231.130.20
Connecting to s3-eu-west-1.amazonaws.com (s3-eu-west-1.amazonaws.com)|54.231.130.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 323617 (316K) [application/json]
Saving to: ‘e46k1qs5dqgru7mwfygvj969c.json’
e46k1qs5dqgru7mwfygvj969c.json 100%[==========================================================================================================================================>] 316.03K 1.20MB/s in 0.3s
2017-05-16 19:46:36 (1.20 MB/s) - ‘e46k1qs5dqgru7mwfygvj969c.json’ saved [323617/323617]
FINISHED --2017-05-16 19:46:36--
Total wall clock time: 0.8s
Downloaded: 1 files, 316K in 0.3s (1.20 MB/s)

patrick@debian:~/casts$ mv e46k1qs5dqgru7mwfygvj969c.json installing_using_asciicast2gif.json
patrick@debian:~/casts$ sudo docker run --rm -v $PWD:/data asciinema/asciicast2gif -s 2 -t solarized-dark installing_using_asciicast2gif.json installing_using_asciicast2gif.gif
[sudo] password for patrick:
==> Loading installing_using_asciicast2gif.json...
==> Spawning PhantomJS renderer...
==> Generating frame screenshots...

You can see some more info on your docker image use the following command

patrick@debian:~$ sudo docker images
[sudo] password for patrick:
Sorry, try again.
[sudo] password for patrick:
REPOSITORY TAG IMAGE ID CREATED SIZE
asciinema/asciicast2gif latest 7589ae2fca68 9 days ago 832 MB

Docker stores these images in layers in /var/lib/docker/overlay2#

root@debian:/var/lib/docker# du -sh overlay2/
845M overlay2/

but that is something for another article on docker
more on Docker on Debian.org

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s