Posted 01.05.2015

Posted 01.05.2015

How to Overcome your Fear of the Terminal

Getting Started

For years, I’ve been afraid of the Terminal. I was scared that I would erase my entire hard drive with a single typo.

But, then I started using grunt. I found it to be so much faster and allowed far more task automation than the tools I had been using previously. IMHO, anything that will speed up your workflow is worth investing in (whether that’s time or money ).

Once I started spending more time in the Terminal, I became more comfortable and confident. Trust me, I still prefer a GUI (graphical user interface), but I’m no longer afraid I’m going to delete my entire harddrive. — And let’s be honest, you could delete your entire hard drive with a GUI too. Drag your harddrive to the trash and click “Empty Trash.” But, nobody in the right their mind would do that. Similarly, you’d have to type a very specific command in the Terminal to delete your entire harddrive and nobody in their right mind would do that either. — Plus if you have a typo in the Terminal, it will tell you and the command won’t run.


So, here are the commands that I’ve found to be the most useful:

NOTE:

When you see examples of command lines in the Terminal and you see a $. Don’t copy the $, it just signifies that it’s the beginning of a Terminal line.

cd stands for change directory. Similar to the Finder where you click on the folder, in Terminal, you just type in the directory that you want:

$ cd Sites

You can type cd .. to go up a level or cd ../.. to go up 2 levels. cd / will take you to your home directory.

The Terminal also supports tab auto completion. So you could type cd De<TAB> and it will fill in cd Desktop for you. Handy!

ls will list all files and directories in your current location.

pwd will show you the current file path to your current location.

mkdir FOLDERNAME will create a folder named FOLDERNAME. mkdir stands for “Make Directory.”

Anytime, you hit the up arrow on your keyboard, it will fill in the last command you ran. Hit it again and it will cycle to the command before that. The down arrow cycles in the opposite direction.

Just to give you an idea of how these commands are used together: when I first open the Terminal, I might type ls to see what my file / folder options are. Then:

$ cd Code/GIT/
$ mkdir NEWPROJECT
$ cd NEWPROJECT

This navigates to the GIT folder and then creates a new directory for a project. Then, navigates inside the folder I just created.

If this is still making your head spin, here’s a WYSIWYG way that I saved until the end: Open up your Terminal type in cd . Then, open up Finder, navigate to the Folder you want to open in Terminal and drag that folder from the Finder onto your Terminal window. It should enter the location for that file path for you. Now, hit <RETURN>. — You’re welcome.


If you’re feeling ambitious, a few other tips and tricks:

I use iTerm2 instead of Mac’s default Terminal. It has a little bit more functionality. My favorite feature, I have a shortcut set up so that any time I hit ALT + Cmd + Space, the Terminal overlays my entire screen. Using the same command sequence will toggle it off. This is great for quickly checking on a grunt or gulp task.

If you want to set this up:

  1. Download and install iTerm2.
  2. Go to iTerm > Preferences. Click on the “Profiles” tab.
  3. Click on the + button in the bottom left. I labeled my profile “Hotkey Window”

    iTerm Preference Window

  4. In the Window tab, I tweaked the transparency, checked Blur, changed the Style to “Fullscreen”, changed the Space to “All Spaces.”

    Screen_Shot_2015-01-02_at_10_26_51_PM

  5. Then, under the Keys tab, check “Show/hide iTerm2 with a system-wide hotkey. As I mentioned, I’m using ALT + Cmd + Space, but do whatever works best for you.

    Screen_Shot_2015-01-02_at_10_27_54_PM

  6. Also check “Hotkey toggles a dedicated window with profile:” and make sure “Hotkey Window” (or whatever you named your custom profile is selected from the dropdown.

Lightning Round.

I’ve always wondered how people were able to customize their Terminal to be all kinds of cool colors.

Then, I was introduced to Oh My Zsh = Awesome.

Even if you could care less about Terminal colors, there are other short cut codes packaged within Oh My Zsh that make Terminal life even better.

I took a leap of faith and trusted Robby Russell and simply ran his automatic installer via Curl. Just copy and paste the following line into your Terminal (remember you don’t need to copy the $ sign):

$ curl -L http://install.ohmyz.sh | sh

Then, you can start Zsh by simply restarting or opening a new command window.

There are plenty of themes to choose from. I went with the agnoster theme and then the colors in my Terminal to use the Solarized theme.

Slow down

Sorry.

To change the theme for Oh My Zsh, copy and past the following line into your Terminal:

$ nano /.zshrc

nano is a simple text editor that runs within the Terminal. So, we’re simply telling it to open our preference file in nano.

Go to the line that’s called ZSH_THEME=“”. Change that line to the name of the theme you want to use, in our case agnoster.

Screen_Shot_2015-01-02_at_10_49_10_PM

Then, type Ctrl + O for “Write Out” (also save). It will ask for the file name, just hit enter to keep the same file name.

Then, type Ctrl + X to exit.

To install the Solaraized theme, click on the download link on their site (also available on their GitHub page).

Unzip the file. Navigate to iterm2-colors-solarized.

Double click on the Solarized Dark.itermcolors file. It should launch iTerm2 with a pop-up message explaining that the color scheme has been loaded into the iTerm2 Preferences (Preferences > Profiles > Colors > Load Presets).

Screen Shot 2015-01-02 at 10.53.41 PM

Make sure your “Hotkey Window” profile is selected and choose “Solarized Dark” from the Load Presets… doprdown.

Screen_Shot_2015-01-04_at_10_29_59_PM

As you begin using the new theme, you may notice some of the characters are not appearing correctly.

I’m using Menlo for Powerline. You can go to their GitHub repository, download, and install the font. There are some other options in the Powerline font repo.

If you’re using a font manager like Suitcase, be sure to mark the font as permanent.

If you’re still having trouble, check the Text tab within iTerm2 and make sure the appropriate fonts are marked.

Screen_Shot_2015-01-02_at_11_01_19_PM

UPDATE JANUARY 25, 2015

Menlo for Powerline stopped working for me. So, I ended up downloading these Powerline fonts from GitHub and installing Meslo, using the same process as described above.


Tripe Bonus.

As I mentioned earlier, “Oh My Zsh” has several shortcuts included. For example, if you’re running Composer, instead of typing composer update, you can simply type cu. Instead of git status, gst. Still not convinced? Here’s one of my favorites: you can type stt and it will open the current directory within Sublime Text. These might not sound like much, but the more you live in the Terminal, the more time it will save you.

All of these shortcuts are considered plugins. You can check out all the ones that available on the Oh My Zsh’s wiki page.

Once you decide which plugins you want to use, you can activate them similar to setting the theme.

$ nano /.zshrc

Find the line that says plugins=()

Include the plugin name within the parenthesises.

Mine reads:

plugins=(git sublime sudo laravel4 Composer bower npm osx)

Last trick.

I have an alias set up so that anytime I type projects into iTerm, it will go directly to my projects folder, where I keep all my code. Essentially, it’s the same as typing cd ~/Code/GIT/ (just in case you were wondering the ~ references your home directory. If you’re not sure what I’m referring to, just type cd ~ and then pwd or ls in the Terminal. You’ll see.)

If you still have your preference file open (nano ~/.zshrc ), look at the bottom. There are a few examples already set up, but commented out (the # in front means the line is commented out). Add a line at the very bottom, below the examples, that reads alias projects="cd ~/Sites".

Then, write out the file (^O) and exit (^X). Restart iTerm2 (or open a new command window). Test it out. Nifty!