How I Use Snippets In iTerm2 To Boost My Productivity as a Software Engineer
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.
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.
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
- Go to iTerm2 > Preferences …
- Go to the Profiles tab and select the Session tab.
- Check the Status bar enabled
- Click on the Configure Status Bar button.
- Drag the Snippet… into the Active Components and click OK.
How to add a Snippet
- Click on the Send Snippet…
- Click on the Edit Snippet…
- Click on the “+” button and add your Snippet with a name and the actual command.
- Click OK to save the Snippet. You will see your new Snippet in the Send Snippet… drop-down menu.
How to export and import snippets collection
- Click on the Send Snippet…
- Click on the Edit Snippet…
- To export, select all the snippets then click on the export icon.
- To import, click the import icon and select the snippets collection file that has the .it2snippets extension (i.e.: snippets.it2snippets).
How to use Snippet from iTem2
- Open the iTerm2
- Click on the Send Snippet… and you will see a dropdown menu.
- Click on the snippet name for the command you want to execute.
- Then you will see the command is pasted on iTerm2 and executed.
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!