Terminal Fu v2
In my last post about terminal, I covered a few basic techniques to really amplify your abilities in the bash prompt. Solid! Customizing the prompt, creating aliases, and the super handy “double bang” have held their own for quite some time. Yet I find there are some things missing from the experience that really keep it from being enjoyable.
I found myself at a standstill trying to get the ridiculous auto-complete system working in bash. I had modified my aliases to be bash scripts so that I could run something like
nproj myNodeProject and cd directly there. Essentially piping two commands together with &&. Without autocomplete, however, the entire experience… well… sucked. So I started down the rabbit hole of COMPREPLY and was feeling defeated.
Enter ZSH , or z-shell. It’s like a terminal prompt on steroids. With powerful features like autocompletion, file globbing, and crazy customization, it was like the void had been filled! I could keep my aliases as I had them and now I had full autocompletion from anywhere! Typing np would take me right to my node project folder. Type
np/ and hit tab and now I could autocomplete on any folder in my node projects directory! Plus, I had found oh-my-zsh, which was an excellent starter set of plugins and themes to get me rolling.
ZSH is a full replacement of bash. I also installed iTerm 2 to get full 256 color support ( I swear it’s prettier ) as well as panel subdivision. So get both oh-my-zsh installed and iterm2 installed. Once that’s set, make sure you head to the configuration for omz in
~/.zshrc. zshrc is basically what bash_profile was in the last tutorial, except that it’ll be more the entry point into the configuration. You can define your additional stuff in files under omz. Run
chsh -s /bin/zsh in iTerm to change the default shell to zsh and then restart iTerm. Boom. You are in! Now try some of the fuzzy autocomplete. For instance, I can type
pp/ca/wp-c/t/c <tab> and zsh finds my “pp” alias and autocompletes to
pp/calendar/wp-content/themes/calendar. Hot stuff! Plus, you don’t even need to type
Here is a list of the plugins I use and their benefit. There are many more available:
- git - gives me short cuts like gss for git status and gl for git pull.
- bower - bi and bs as well as auto-completion
- brew, npm, coffee, node - autocomplete helpers
- wd - or warp drive. Shortcuts for bookmarking and fast traveling to directories
- sublime - sublime text shortcuts stt, open current directory, or st to open a file
- common-aliases - full of useful shortcuts for common commands like file listing. I did end up overriding several however.
- osx - this one has a super cool cdf to cd to the current top-level finder directory as well as quick-look for quick-looking a file from the shell.
- web-search - web searching from terminal! just type google
and it’ll open the search in your browser.
Sometimes a plugin has a command ( or lack thereof ) that you really want to have. OMZ will look to its custom folder for any files named the same as a plugin. For instance, I overrode some common aliases by creating a file called common-aliases.plugin.zsh which is loaded in automatically. Keeps things cleaner this way. Here are my overrides:
Plus, you can define your own custom commands in any other zsh file in that directory. I created my.zsh and fed it (for example):
With np the way it is, it’s like an alias that’s really more like a pre-typed command. I can just type np/ to go to my node projects directory, or
np/<tab> to autocomplete on that directory. rst restarts the shell in case I change anything in the zshrc or other files. omz opens my zsh config in sublime text. Then there are two additional git utilities. Simple!
There is so much more to be explored. File globbing, global aliases, programmable features directly in shell. It’s a wonder I didn’t try this before! Now get to it!