Pump up your terminal
A couple of months ago, a friend of mine showed me his setup working with the terminal on macOS. It totally blew me away. I was used to the bash shell and used the terminal only if I really needed to. In this article, I want to share with you my new “productive” terminal setup. I hope you can get some inspiration from this.
Get a new command-line client
First of all, you need a great command-line client. The macOS built-in Terminal is ok but misses some features. I now use iTerm2 and I love especially this features:
- Split Panes: You can divide a tab into multiple panes, each one showing a different session. I use this feature a lot when I have to deal with multiple ssh sessions.
- Search: iTerm2 has great search implementation. Thanks to the highlight it is easy to see the matched words. Moreover, the search supports even regular expression, which some of us developers love!
- Instant Replay: Have you ever launched an interactive program and forgot something you entered? Instant Replay will save you every time. Just travel back in time and look up what you forgot.
PS: If you use Windows you can try Cygwin.
Get rid of bash
Now it’s time to get rid of the good old bash shell. I use ZSH (Z shell), which gives me plenty of improvements to bash. Again a list of my favorite ones:
- Automatic cd: Stop typing cd every time you need to change the directory. Simply type the directory name!
- cd 2.0: When you write `cd` and then press tab, bash will show you a list of files and directories. Since you can’t change the directory to any file, ZSH will show you only directories.
- Spelling Correction: If you make a tiny spelling mistake entering your commands ZSH will fix it for you.
If this convinces you to switch to ZSH, run the following command to install it (using Homebrew):
brew install zsh
and set it as your default shell
chsh -s /bin/zsh
If you are using Cygwin refer to this article to check how to install zsh.
Give superpowers to your ZSH
Moving to ZSH we already switched to a much more powerful shell. But we want more. And to add even more power to ZSH we have to install Oh My ZSH.
Run the following snippet in your ZSH to install it.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Oh My ZSH comes with plenty of plugins which can make you feel like a developer with superpowers:
- completion plugins: if you install completion plugins (e.g for git or brew) ZSH will know which arguments the package has and will support you with autocompletion.
- z: by far my favorite plugin. Simply type
z
followed by the first couple of characters of the directory you want to switch to. For instance, if you want to switch to the Documents folder typez Doc
and press Tab. The plugin will automatically bring you to the directory starting with “Doc” you use the most. Feels like teleportation, doesn't it? - alias-finder: Want to learn some new aliases? This plugin is your friend. Type
alias-finder
followed by the command you want to learn aliases for. Alias-finder will tell you if there are any aliases for the command.
Obviously there are a lot more plugins. I encourage you to visit their GitHub wiki to find the right plugins for you.
To enable the plugins I mentioned above you have to edit your ~/.zshrc
file. Update the plugins section to plugins=(git brew z alias-finder)
.
I have been using this setup for a while now and I use the command-line as often as I can. I hope this article can help you get more productive when you use the command-line for dev work. If you find some features of zsh or plugins of Oh My Zsh that you like, let me know in the comments. I’m always looking for more superpowers 😉.