The command line is increasingly becoming a part of every web developer’s workflow. With tools like Grunt, Gulp and Bower leveraging the increase in productivity that comes with working in the command line, we are seeing it become a much more friendly and comfortable place for beginners and experts alike.
This article provides insight into some of the best tools to use in your day-to-day workflow in the command line and gets you started with a totally customized setup. Also, please make sure to check out my series on how to become a command-line power user1, available for free, of course.
Getting The Right Terminal Link
Before we can start using ZSH, Z and related tools, getting the right terminal application up and running would be extremely helpful. The default Terminal and Powershell applications on OS X and Windows leave much to be desired.
For OS X users, iTerm 22 is recommended as a replacement for OS X’s default Terminal. iTerm 2 introduces some features that are missing in the regular terminal, including commands you would regularly use in your text editor. This includes pane splitting, custom color schemes, paste history, fine-grained control over hotkeys, together with dozens3 of other handy preferences that you will find useful as you become more comfortable in the terminal.
On Windows we have the built-in PowerShell. Most users find this quite different to the interface of the typical UNIX servers used to host websites; it’s also rarely addressed in online tutorials. For this reason, it’s recommended to use an emulator that provides a closer experience to a real UNIX command line, like Linux and OS X do.
You have a couple of options here. The easiest would be to install Cmdr, which provides Git integration, custom prompt and color schemes out of the box. For most, this will be more than enough to get started with all major web development tooling. It cannot, however, do any of the ZSH and Z that we will be exploring below.
For a full-blown UNIX emulation, there is Cygwin4 which allows us to run all UNIX commands as well as to work with Oh-My-ZSH. It’s not for the faint of heart, but if you are fairly comfortable with Windows, it might be worth trying out. Alternatively there is the all-in-one OH MY CYGWIN5, which might speed up your installation process.
Use ZSH and Oh-My-ZSH Link
When you start a terminal application, whether it be on your server or your local computer, it is running a shell called Bash. Bash is by far the most popular shell and comes with pretty much every UNIX-based operating system. There are, however, alternatives to Bash that make using the terminal faster and more comfortable for web developers.
Installing Oh-My-ZSH is very simple. Simply run the following command and restart your terminal:
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
Now, each time you start a terminal session, you will be using ZSH rather than the default Bash!
ZSH Settings Link
Before jumping into the next few sections, we need to know about ZSH settings. These are stored in a
.zshrc file located in your home directory. It’s a hidden file, so you might not see it in your home directory, but you can view it by running
open ~/.zshrc from the terminal. Swap out
open with your favorite editor command, such as
Now, we aren’t making any changes to this file just yet, but leave it open. Whenever you make a change to this file, you need to source it in order for the changes to take effect in your terminal. To do this, you can either close the current tab and open a new one or run the
source ~/.zshrc command from the terminal.
Terminal Customization Link
Customizing what your terminal looks like is one of the best things you can do. Not only does it make you look like a bad-ass coder, but it can greatly improve readability via different colors. It can also improve productivity by displaying important information related to file path, Git status and more!
Prompts are the line(s) of text shown when you are about to type something into the terminal. Your prompt provides useful information related to your project, such as the current version of Ruby, Node.js and so on, the current status of your Git repository, the outcome of the last run task, as well as the current working directory.
You can customize your path into oblivion, but chances are that someone has created a prompt that already suits your needs.
Your ZSH theme is set in the few lines of your
.zshrc file. Look for something like
ZSH_THEME="robbyrussel" — this is the default theme that comes with ZSH. I recommend setting this to
ZSH_THEME="random", which will randomly assign a theme each time you open a new terminal tab or run
source ~/.zshrc. Run this a few times until you find one you like; you can find the current theme name by running
You can browse all the ZSH themes and prompts in the wiki9. Because there are hundreds of themes, not all of them come with ZSH by default. Any you want will need to be downloaded and placed in
~/.oh-my-zsh/themes; Because this is a hidden directory, you can access it by running
Here are a few popular themes:
Color Schemes Link
Now, the prompts define the standard color to be used, but we’ll use iTerm2 themes to customize what those colors actually look like. By default, the themes come with your basic red, green, yellow and blue, but we can tweak those to be the exact variants that we want.
You can edit the colors or even make your own theme in “Preferences” → “Profiles” → “Colors,” or grab one of the existing themes already out there.
File Tabbing Link
So, now that our terminal is looking great, what can we actually do with ZSH and related tools? Probably one of the most useful features of ZSH is that it enables us to list and tab through files and folders. If you have ever tried to perfectly spell the name of a file, struggled with the case or fought with an impossibly long list of folders with spaces in it, you know the pain and limitations of Bash.
Folder and file tabbing works with any terminal command:
subl, etc. But for the purposes of this tutorial, let’s use
cd for folders and
open for files.
Go ahead and type
cd (note the space after
cd), and hit the “Tab” key twice. You can now use your arrow keys to move over, up and down through the files and folders. To select a folder, hit “Return.” You can now hit “Tab” and “Tab” again to discover subdirectories or hit “Return” to run the command.
This also works for completing file and folder names. Let’s say I’ve got two folders,
/Capitalize. If I type
cd c and then hit “Tab” twice, I’ll be able to cycle through all of the folders that start with C. You’ll noticed it’s case-insensitive. This is extremely helpful when you have many files with similar names.
Finally, this also works with command names whose names you might not totally remember. For example, if you’re working with MongoDB, 13 commands are associated with it:
mongofiles mongoimport and so on
mong and hitting “Tab,” you’ll see all available commands that start with
ZSH Plugins Link
ZSH allows you to extend built-in functionality by adding plugins, and it actually ships with a bunch of fantastic ones. To enable a plugin, open your
.zshrc file and scroll down until you see the spot where active plugins are defined. To add a new one, just type the name between the parentheses, making sure to include a space between each name.
plugins=(git cloudapp node npm bower brew osx extract z)
Once you’ve added a plugin, you’ll need to either run
source ~/.zshrc or open a new tab.
Some recommended ones are:
Enabled by default with Oh-My-Zsh, this enables Git aliases, tab completion and descriptions of all Git commands.
Enables uploading of files to CloudaApp right from the command line.
Opens the Node.js API for your current version in your browser.
Adds autocompletion to npm, displaying all npm commands.
Adds autocompletion for Bower commands.
Adds autocompletion and descriptions for all Brew commands.
Enables a number of Finder commands26 that are accessible via the terminal.
Unzip all types of compressed files.
More on this in the next section!
Using Z To Jump To “Frecent” Folders Link
Z isn’t part of Oh-My-ZSH, but it’s the perfect companion for anyone who heavily uses the command line. The idea behind Z is that it builds a list of your most frequent and recent — “Frecent” — folders and allows you to jump to them quickly in one command, rather than having to tab through a nested folder structure.
To install it, make sure Z is included in the plugins list from above. While this works for most, some users have trouble getting this to work. If that is the case, download download Z28 and put it in your home directory so that it’s located at
~/z.sh. Then, in your
.zshrc file, include the following and then source your
.zshrc file again.
# include Z, yo . ~/z.sh
Once it is installed, continue with your regular traversing of directories with your
cd command. Z is watching where you frequently and recently have been, and is building a weighted list of directories.
After a few hours of moving around, you can use the
z command followed by a word that is in your directory. It uses fuzzy matching to figure out what folder you are trying to get to, and it’s almost always right!
z stylesmight bring you to
z pizzamight bring you to
z pizza stylesmight bring you to
z 303might bring you to
More, More, More! Link
As developers, we know how important it is to sharpen our tools and continually add new ones to our workflow. The command line is one of the best tools you can master as a developer. With this article, we are just scratching the surface of what we can do with the command line. Check out Command Line Power User30 for all 11 free videos about getting comfortable with the command line.
- 1 http://commandlinepoweruser.com/
- 2 https://www.iterm2.com/
- 3 https://www.iterm2.com/features.html
- 4 https://www.cygwin.com/
- 5 https://github.com/haithembelhaj/oh-my-cygwin
- 6 http://ohmyz.sh/
- 7 https://www.smashingmagazine.com/wp-content/uploads/2015/07/01-cobald2-opt.png
- 8 https://www.smashingmagazine.com/wp-content/uploads/2015/07/01-cobald2-opt.png
- 9 https://github.com/robbyrussell/oh-my-zsh/wiki/themes
- 10 https://www.smashingmagazine.com/wp-content/uploads/2015/07/02-agnoster-opt.png
- 11 https://github.com/robbyrussell/oh-my-zsh/wiki/themes#agnoster
- 12 https://www.smashingmagazine.com/wp-content/uploads/2015/07/02-agnoster-opt.png
- 13 https://www.smashingmagazine.com/wp-content/uploads/2015/07/03-cobalt2-opt.png
- 14 https://github.com/wesbos/Cobalt2-iterm
- 15 https://www.smashingmagazine.com/wp-content/uploads/2015/07/03-cobalt2-opt.png
- 16 https://www.smashingmagazine.com/wp-content/uploads/2015/07/04-bira-opt.png
- 17 https://github.com/robbyrussell/oh-my-zsh/wiki/themes#bira
- 18 https://www.smashingmagazine.com/wp-content/uploads/2015/07/04-bira-opt.png
- 19 https://github.com/powerline/fonts
- 20 https://www.smashingmagazine.com/wp-content/uploads/2015/07/05-bira-opt.png
- 21 https://www.smashingmagazine.com/wp-content/uploads/2015/07/05-bira-opt.png
- 22 https://www.smashingmagazine.com/wp-content/uploads/2015/07/06-schemes-opt.png
- 23 https://www.smashingmagazine.com/wp-content/uploads/2015/07/06-schemes-opt.png
- 24 https://github.com/wesbos/Cobalt2-iterm
- 25 https://github.com/search?q=iterm+extension%3Aitermcolors&ref=searchresults&type=Repositories&utf8=%E2%9C%93
- 26 https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#osx
- 27 https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
- 28 https://github.com/rupa/z/blob/master/z.sh
- 29 https://github.com/rupa/z
- 30 http://CommandLinePowerUser.com