code drip ☕

5 Terminal Tricks I wish I knew sooner

July 21, 2019

As a developer, your terminal is kind of like your living room

  • you spend a disproportionate amount of time there
  • a little houskeeping can equal a lot of happiness

my room

so here’s 5 low effort, high leverage bash terminal tricks

Over time, you accumulate little tricks to optimize your terminal…

Here are some low-effort, high-leverage tricks I’ve picked up over time.

Given how simple they are, you can start using all of them right now, with no learning curve.

1) alias everything

You probably know about aliases, and maybe even use a few.

But you should probably be using it more, a lot more.

For almost any command I run multiple times a day, I’ll make an alias by editing ~/.bashrc

A few examples: Part of my .bashrc

and so on.

Is it hard to remember all these aliases?

Actually, surprisingly not, after you use them a few times.

Just add your most common ones at first build your way up.

2) window stacking

I use iTerm as my terminal of choice.

I can’t remember when I started using it, but I do know that its window stacking feature constantly in use for me.

I use it to logically group things while multi tasking, or to run multiple servers / processes at the same time

Organized terminal space 😱 5 terminals, no problem

Looks cool too (imo)

open a new stacking window

  • horizontally with cmd + d
  • vertically with cmd + shift + d (my go-to)

3) VI(m) syntax highlighting

Every dev should at least know some basic VIM for sever configuration, quick edits, etc.

Syntax highlighting helps you write less errors in VIM and there are no installs required.

It’s such a simple trick that I am embarassed it took me so long to figure out.

Just open (or create) ~/.vimrc with vi ~/.vimrc

just add one line: :syntax on; and save

Part of my .bashrc

Subtle, but way better (imo)

If you want to further customize VIM, there are tons of VIM plugins.

4) PS1 customization

Your bash PS1 prefixes every command you type with this nifty tool:

Create a custom prefix with the bashrc generator

one of the sections from the generator

Then paste it by opening vi ~/.bashrc

Apart from prefixing your commands with your favorite color, you also get the directory name right there, no more pwds required.

here’s mine: my ps1 is personalized

5) jq

prints json files and streams into nicely formatted, colorized outputs.

For this to work, just.

brew install jq

then just pipe a json call into jq by appending | jq .

curl https://entrylevelsoftwarejobs.com/api/jobs | jq .

check out the before and after

before and after

you can also use jq on a file,

for example jq . package.json

…can be used for getting specific properties from JSON files…

jq .scripts package.json

some beautiful json

…and even more if you want to check out the docs.

tl;dr

  1. create aliases for everything in ~/.bashrc to speed everything up
  2. stack windows in iTerm with cmd + (shift) + d
  3. turn on vi syntax highlighting with :syntax on in ~/.vimrc
  4. use jq . to format and colorize json
  5. you can generate a custom command prompt here

That’s it!

Hope at least one of these was new for you