How I Use Snippets In iTerm2 To Boost My Productivity as a Software Engineer

Allen Tuh
Reflex Media
Published in
5 min readDec 22, 2022

If you are an experienced software engineer, you probably are using tools like iTerm2, Terminal, or Command Prompt as part of your daily work routine. While nothing wrong using them as is, there is a much smarter way to get the job done quicker, using iTerm2 Snippets.

Photo by Kevin Ku on Unsplash

What is a Snippet?

A snippet is a saved bit of text that can be pasted quickly when you click on it. The text can be anything from a paragraph to a command.

Snippets in iTerm2

Here are some examples of how using Snippets can help with your productivity:

Limited brain RAM capacity

Are you frustrated having to to go back to StackOverflow just to copy-paste the same command over and over again, just because you cannot remember the exact command? Since Snippets holds all of my commands, all I need to do is just browse through the snippets dropdown menu and click on the snippet name that I want to execute. Just be sure to use a name that is easy to remember though. This shaves off 25% of my time on StackOverflow :D

Quick easy access to all common commands

Do you save all your useful commands all over the place e.g. Notes, Google Drive, Slack, paper and etc? With snippets, I can quickly execute any command I need instantly with a single click. Snippets are my one-stop store for all my useful commands.

Avoid executing the wrong command

Each time we type or copy-paste a command in the terminal, we are prone to make mistakes. This is a serious matter if you are especially dealing with the production environment. Thus, making these critical commands into snippets will guarantee that when you click on one of them, it is going to execute the exact command you intended. No more silly mistakes and typo errors, yeah!

Reduce repetitive typing

In my daily work routine, I find myself typing the same command multiple times, like when running Codeception test cases. With Snippets, I simply click on the Codeception command without much typing. This enables me to have more time to focus on producing better code.

Sharing is caring

More often than not, the snippets collection you have is likely useful to others as well. Why not share your collection with them? iTerm2 enables you to export and import your snippets collection easily. Find out how to below.

How to enable Snippet to the status bar

  1. Go to iTerm2 > Preferences …
  2. Go to the Profiles tab and select the Session tab.
  3. Check the Status bar enabled
  4. Click on the Configure Status Bar button.
  5. Drag the Snippet… into the Active Components and click OK.
Check the Status bar enabled
Drag the Snippet… into the Active Components and click OK

How to add a Snippet

  1. Click on the Send Snippet…
  2. Click on the Edit Snippet…
  3. Click on the “+” button and add your Snippet with a name and the actual command.
  4. Click OK to save the Snippet. You will see your new Snippet in the Send Snippet… drop-down menu.
Click on the Send Snippet…
Click on the Edit Snippet…
Add a new Snippet and click OK to save it

How to export and import snippets collection

  1. Click on the Send Snippet…
  2. Click on the Edit Snippet…
  3. To export, select all the snippets then click on the export icon.
  4. To import, click the import icon and select the snippets collection file that has the .it2snippets extension (i.e.: snippets.it2snippets).
Export snippets collection
Import snippets collection

How to use Snippet from iTem2

  1. Open the iTerm2
  2. Click on the Send Snippet… and you will see a dropdown menu.
  3. Click on the snippet name for the command you want to execute.
  4. Then you will see the command is pasted on iTerm2 and executed.
Execute snippet in iTerm2

Sample of useful Snippets

Here are some examples of the more commonly used snippets as polled by my peers.

Access MySQL

mysql -uroot -p'your_password' 

Enable logging in MySQL

SET GLOBAL general_log=1;
SHOW VARIABLES LIKE '%general%';
exit

Access MongoDB

mongo -umy_app -p'your_password' --ssl --host 'documentdb-myproject-test.cluster-c2kexzo0yxou.ap-southeast-1.docdb.amazonaws.com' --sslCAFile rds-combined-ca-bundle.pem

Navigate to another directory

cd /var/www/destination/folder

Turn on NGROK

ngrok http -host-header=rewrite api-local.myapp.com:80

Start JMeter

bash /Users/johndoe/Downloads/jmeter/bin/jmeter.sh

Running JMeter report

rm /Users/johndoe/Desktop/jmeterResult.csv
rm -r /Users/johndoe/Desktop/jmeterReport
bash /Users/johndoe/Downloads/jmeter/bin/jmeter.sh -n -t /Users/johndoe/Downloads/jmeter/bin/examples/YourTestPlan.jmx -l /Users/johndoe/Desktop/jmeterResult.csv -e -o /Users/johndoe/Desktop/jmeterReport

Running Codeception (for Laravel)

vendor/bin/codecept run

Add a new feature for BDD Codeception (for Laravel)

php vendor/bin/codecept g:feature functional 

Generate Snippets for BDD Codeception (for Laravel)

php vendor/bin/codecept gherkin:snippets functional

Turn on database logging for the reader node (for Laravel)

DB::connection('mysql_read')->enableQueryLog();

Get the logging records from the reader node (for Laravel)

DB::connection('mysql_read')->getQueryLog();

So have you used Snippets with your iTerm2? Do you find mine useful? Share with me some of the powerful Snippets you have on your set up!

--

--