Recording terminal session is never an easy task with traditional screen recorder tools. We may record for tutorials, presentations, and GIFs but end up in a blurred video that isn't clear with the colors, resolution, speed, etc. Today, I will introduce you to a tool/platform which solves all such problems and has features to record, share and embed terminal sessions.
Asciinema installation
It can be installed with various methods and can be build from the source code found on github.
Install latest version with pip:
$ sudo apt update
$ sudo apt install python3 python3-pip
$ pip3 install asciinema
Install with available packages:
Debian - apt-get install asciinema
Ubuntu - apt-get install asciinema
Alpine - apk add asciinema
Arch Linux - pacman -S asciinema
Kali Linux - apt-get install asciinema
Fedora - dnf install asciinema
OS X - brew install asciinema
Raspbian - apt-get install asciinema
Dockerfile - dockerfile.run/asciinema
Docker - docker run cmd.cat/asciinema asciinema
asciinema syntax
$ asciinema [-h] [--version] {rec,play,cat,upload,auth} ...
asciinema usage
rec |
Record terminal session |
play |
Replay terminal session |
cat |
Print full output of terminal session |
upload |
Upload locally saved terminal session to asciinema.org |
auth |
Manage recordings on asciinema.org account |
-h , --help |
show this help message and exit |
--version |
show program's version number and exit |
Command examples
1. The most basic command record terminal sessions and upload it to asciinema.org with rec
option:
$ asciinema rec
2. Specify a file with above command to record terminal session and save to local file (with extension .cast
):
$ asciinema rec demo.cast
3. To record terminal and upload it to asciinema.org, specifying title use -t
flag as follows:
$ asciinema rec -t "My git tutorial"
4. To record terminal to local file, limiting idle time to max 2.5 sec, you may use the -i
flag as follows:
$ asciinema rec -i 2.5 demo.cast
5. To replay terminal recording from local file, use play
option as follows:
$ asciinema play demo.cast
6. To replay terminal recording hosted on asciinema.org directly to your terminal by specifying the URL as parameter:
$ asciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8
7. To print full output of recorded session, use the cat
option as follows:
$ asciinema cat demo.cast
Embedding asciinema recorded terminal sessions
To embed your asciinema recording into a webpage, you can follow these steps:
- First, you need to upload the Asciinema recording on a server. You can do this by using the asciinema upload command to upload the recording to the asciinema.org server, or you can host the recording on your own server by copying the JSON file that contains the recording to the server.
- Once you have the asciinema recording hosted on a server, you can use the following HTML code to embed the recording into a webpage:
<iframe src="https://asciinema.org/a/<recording id>" width="640" height="480"></iframe>
Replace <recording id>
with the ID of the asciinema recording that you want to embed.
Generate gif from terminal cast
To generate a GIF from a terminal cast using asciinema, you can use the asciicast2gif
command-line tool, which is part of asciinema package. This utility allows you to create a GIF from an asciinema recording by specifying the input file and the output file.
Here's an example of how to use asciicast2gif
to generate a gif from an asciinema recording:
asciicast2gif input.json output.gif
This will create a gif file called output.gif
from the asciinema recording stored in the input.json
file.
You can also customize the appearance of the resulting gif by specifying options such as the width and height of the GIF, the frame rate, and the font size.
asciicast2gif --width 800 --height 600 --font-size 14 --frame-rate 15 input.json output.gif
This will create a gif with a width of 800 pixels, a height of 600 pixels, a font size of 14 points, and a frame rate of 15 frames per second.
Conclusion
In conclusion, asciinema is a useful tool for creating and sharing terminal recordings. It allows you to record terminal sessions and play back the recordings in a variety of formats, including HTML, GIF, and JSON.