Termshot - Take Image Screenshot of Command Line Output

In this article, I'll show you how to turn a command line output in Linux into an image using Termshot. Termshot is Linux tool which turns a cli command's output into a screenshot including colors and interactive text. This is of the essence if working on something that you need to screenshot for sharing, reference or documentation purposes. Sometimes you would copy terminal output in a text format but when you paste it on a different platform like CMS, it will lose original formatting and its colors giving it an atrocious look.

Additionally, Termshot crops the output image to best fit its content but has a maximum width. This setup has been tested on an updated Arch Linux. For a different Linux distribution, ensure you have the required dependencies first before getting the termshot script.

Install termshot on Arch Linux

nbsp;sudo pacman -Syu # update system $ pacaur --needed --noconfirm --noedit -S termshot

With plain yaourt, use:

$ yaourt --noconfirm -S termshot

The installation may take a while since it builds from source and has to install the following dependencies first:

There are a number of options which can be passed to the termshot command, namely:

--maxWidth|-w [width] --> Limit the maximum outputted image's width to [width] pixels." Exceeding content is wrapped. The default is 1280
--filename|-f [filename] --> The file name to store the resulting image." Default: \$(date "+termshot-%Y%m%d-%H%M%S.png")"
--outputDir|-o [directory] --> The folder where the resulting image will be stored."Default: \${HOME}/Pictures"
--help|-h --> Display help page.

Using Termshot

Once the installation is complete, you can start using termshot by typing the command termshot on the terminal. See above command options for what to pass to it.

$ termshot ls -l --color=auto /

By default, the image is saved in the ${HOME}/Pictures folder and is timestamped but you can change this as you desire. The example below will save the image to a different directory.

$ termshot -o ~/Desktop ping -c 5

To change the maximum width of the image, use:

$ termshot --maxWidth 1080 curl

It's important to give the image a meaningful name. See example below for name modification.

nbsp;termshot -f ping-test.png ping -c 3 mysite.com

This will make it easy for you to reference saved images by names.

Wrapping Up

To conclude, Termshot appears to solve a problem of transferring Linux command outputs with its colors intact. Though there are screenshot applications which you can use, Termshot is more attractive because of the fact that you use it on the fly with auto size detection. No need to manually crop images or select terminal window as common on other screenshotting applications, which makes things a little faster.

Leave a Comment