Embrace the Terminal

April 19, 2015

Listen to this blog post:

As a designer or developer person who uses a computer, the terminal is your best friend! But understandably, that big white or black box with a ticking pointer can appear very intimidating. Especially when filled with red error messages or when entering commands blindly from the internet (don’t do that!).

Education is key here. When you understand what some basic commands are doing, you can overcome terminal-dation (just go with it) and really improve your work flow!

Please Note: The following article focuses on unix-based systems (like Mac) only. I can’t help you with Windows. Sorry!

Working the Command Line

If you’re only using the terminal sometimes — maybe to run task runners (like Gulp or Grunt), and use Github, there are a few key commands that will help you with your work flow.

Moving Around the Terminal Prompt

Controlling Processes

Dealing with Files

Editing Files


My terminal

I'm using a modified version of the robbyrussell zsh theme.

Customizing Your Terminal

Z Shell (Zsh) is a Unix shell that boosts the power of your typical Bash prompt. Specifically, it has better tab completion among other things, or so I hear. You will now have to edit your .zshrc instead of .bashrc profile for aliases and some other tasks. Oh My Zsh is a community-driven effort to provide customizations for Z Shell, and can really transform your terminal experience. Not only are there tons of beautiful themes, but it allows easy and invaluable git integration that will surely change your life. You can install it with one simple script:

curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

Custom Commands

Writing your own terminal shortcuts is easy and fun! You can do this in a few ways. I’m going to assume you’ve installed Z Shell and Oh My Zsh from the previous section (because you should!) and it would take a while to go through every method to add aliases. So I’ll talk about two places you can write your aliases.

Aliases

The first is in your .zshrc file (typically located in your root directory, so you can access it with vim ~/.zshrc or subl ~/.zshrc or open ~/.zshrc (look at all of the options you now have!)). Oh My Zsh will have some configuration settings you can uncomment in there, and you can also create aliases in this file begining with alias!

The second thing you can do is create a new shell script file and link to it from the .zshrc file using source. For example, if I make a file within the same directory, I would put source "/Users/unakravets/.aliases.sh" in the .zshrc file. All of my aliases would go into aliases.sh. This allows for a better file organization and overall cleaner system.

Whichever way you do it, let’s see an example. This alias will open up the emoji cheat sheet. Super important for git commit messages and life in general:

# open up emoji cheat sheet in browser
alias emojis="open http://www.emoji-cheat-sheet.com/"

Here’s another example. This alias gives me a beautiful visualization of my git history and branches right inside of my terminal. All i’d have to do is type git-pretty and BAM!:

# pretty visual git history
alias git-pretty="git log --graph --oneline --all --decorate"

Functions

Functions allow for some great extensibility of custom commands in your terminal. Here is an example of a basic function that makes a folder and then opens up into it:

function mkd() {
    mkdir "$@" && cd "$@"
}

You can get a bit fancier with functions by including loops and logic. Here is a function I wrote to add items to my content-I-want-to-read/watch/etc list in my Open Source Personal Goals Repo:

# add to content list (opens content list folder in vim)
# i.e. pg-add blog-post or pd-add resource
function pg-add() {
  if [ $# -eq 0 ]; then
      print "Oops. Please enter a content type! (i.e. pg-add video)"
    else
      vim ~/Desktop/Dev/personal-goals/content-list/"$1"s.md
  fi

}

For more information about what's going on here, check out this blog post.

Let’s break down some of that function syntax:

You can use functions and aliases to do pretty much anything and really tailor them to your personal work flow. Open a specific folder often? Write an alias so you can access it from anywhere. Once you start, you’ll find more and more ways to optimize your setup and love the terminal!

tl;dr: Terminal is your friend. Embrace it!