Increase your terminal productivity
27 May 2019 Terminal

The terminal
Most developers and designers use the terminal everyday but it can be tough to learn all the pre-written aliases that speed things up for you.
I'll go over some of the aliases and techniques I use to speed things up a bit 🚀
Assumptions
I'm on OSX and using Homebrew, ZSH and iTerm2 as my terminal.
Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install iTerm2
brew cask install iterm2
Install ZSH
brew install zsh
Out of the box
Now that you have these three things installed, it is already easier to do a lot of stuff
Homebrew
As you saw above, installing applications is really simple with Homebrew. It's also as easy to update and remove them.
ZSH
Now that you're using ZSH, auto_cd
will be enabled by default.
This means that instead of typing cd mydir/anotherdir
, you can omit the cd
altogether.
Tab completion should also be set up so if you start typing a command or a filepath, hit tab and options will be shown to autocomplete your command.
iTerm2 themes
You can customise iTerm2's themes so that they look pretty cool:

Check out this link for instructions on how to style yours.
Aliases
You may find yourself typing the same commands over and over again, maybe even a sequence of commands.
Aliases allow you to write your string that will perform any given command.
Now that you're using ZSH, in your home directory (cd ~
) there will be a hidden file .zshrc
.
Open that file:
open ~/.zshrc
In there you'll see a bunch of config code, most of it commented out. Have a look through it to see if there's anything in there you'd like to enable.
Once you're done, scroll right to the bottom and you'll see some aliases.
You'll now be able to write your own aliases using the following syntax.
alias myaliasname = "command(s)"
My own .zshrc
file looks like this:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias installRun = "npm i && npm run dev"
alias ls = "ls -a"
alias share = "php -S '10.54.4.120:3000'"
You'll can see my installRun
alias contains more than one command that I've strung together using the &&
operator.
Git
I find the built in alias gcam
particularly useful when commiting files to my git repositories.
It means that instead of writing:
git add .
git commit -m "My commit message"
git push
I can simply write:
gcam "My commit message" && gp
Some other useful built in aliases that speed up your git workflow:
# Check the status of your working tree
gst [git status]
# Pull from origin
gl [git pull]
# Push to origin
gp [git push]
# Switch to branch
gco <branchname> [git checkout <branchname>]
# Switch to new branch
gcb branchname [git checkout -b <branchname>]
# Push new branch and set origin to a new branch of the same name
gpsup [git push --set-upstream origin $(current_branch)]
# Fetch origin
gfo [git fetch origin]
# Stage all changes
gaa [git add --all]
# Commit with message
gcmsg "Your commit message" [git commit -m "Your commit message"]
# Stage and commit everything in your working tree
gcam "Your message here" [git add --all && cit commit -m "Your message here"]
The list of git aliases is huge so it's worth looking them up to decide which are most useful to you.
Have fun!