Skip to main content
Find Writers Products Industries Plans Become a Writer 1 (866) 501-3116 Sign In Get Started

Products

Blog Posts Press Releases Web Pages Product Descriptions Newsletters
Transcriptions Social Media Posts Video Scripts Custom Projects Content Tune-Ups
Ad Copy Ebooks Editing Q&A Content Whitepapers
Facebook Post Instagram Post

Industries

Art & Design Automotive Building Materials Cannabis Career Construction Counseling Customer Service Dental Education Energy & Environment Engineering
Fashion & Beauty Family Practice Food & Beverage Gaming Health & Wellness Healthcare Higher Education Home & Garden Human Resources Injury Law Interior Design IT & Security
Insurance Legal Manufacturing Media & Entertainment Medical Law Nutrition Parenting Payments Personal Finance Real Estate Relationships
Retail & Ecommerce Religion & Spirituality Restaurant and Bar SaaS Sales Senior Services Software Sports & Fitness Technology Transportation & Logistics Travel
x Close Menu Find Writers Products
Blog Posts Press Releases Web Pages
Product Descriptions Newsletters Transcriptions
Social Media Posts Video Scripts Custom Projects
Content Tune-Ups Ad Copy Ebooks
Editing Q&A Content Whitepapers
Facebook Posts Instagram Posts
Industries
Art & Design Automotive Building Materials Dental Gaming Fashion & Beauty Family Practice Cannabis Career Construction Counseling Customer Service Injury Law Interior Design IT & Security Retail & Ecommerce Education Energy & Environment Food & Beverage Personal Finance Healthcare Health & Wellness Higher Education Home & Garden Human Resources Transportation & Logistics Insurance Legal Manufacturing Media & Entertainment Medical Law Nutrition Parenting Payments Real Estate Religion & Spirituality Restaurant and Bar SaaS Sales Senior Services Software Sports & Fitness Technology Travel Relationships Engineering
Plans Become a Writer Login Get Started 1 (866) 501-3116
  1. Blog Home
  2. Development
  3. Sylvain Niles
  4. Bash is dead... Long live ZSH!

Bash is dead... Long live ZSH!

Over the years I've flirted with several different shells. During the 80's on System V I used csh, later I spent years working on Solaris in tcsh (oooh tab completion!), but as Linux became the main operating system of choice I switched to bash. It seemed like a good choice at the time, as it has several nice features and is the default on most systems, including OS X. However, it wasn't long until I started noticing the cool new kid on the block: zsh.

I admit, I was originally interested in zsh because of the flashy command prompt I saw co-workers using-wow is that really your laptop battery life displayed as hearts from zelda in the command prompt??-but once I dove in I found all sorts of awesome stuff!

Recursive Globbing


How many times have you been looking for a file but can't remember where in your home dir it's stored? You can resort to the find command, but it's clunky and not very intuitive. Instead with zsh, you can find it quickly and efficiently:
+-@Sylvains-MacBook-Pro.local ~/temp


+- ls -la **/*.txt

-rw-r--r-- 1 sylvain staff 0 Sep 17 17:31 1.txt

-rw-r--r-- 1 sylvain staff 0 Sep 17 17:31 2.txt

-rw-r--r-- 1 sylvain staff 0 Oct 1 13:49 baz/foo/file_im_looking_for.txt


Suffix Aliasing


In GUI interfaces like Windows or OS X you have the ability to double click on a file in order to launch the appropriate application to open that file with. In zsh you can instead set suffix aliases to accomplish something similar:
alias -s rb=vim

Now from my shell I can just type:
~/temp/sample.rb

And voila, vim will launch and edit the file.

Hash Support


If you do a lot of development in ruby and its compatriots, you've probably come to rely on hashes as a very versatile data structure. After all, being able to work with them in your shell scripts makes them much more powerful and allows you to more intuitively aggregate data instead of having to set up large number of accumulator variables. Additionally you're able to do things like list all the keys and/or values in the hash, something you can't do in bash without knowledge of all the variables and explicitly calling each one.

Sexy Command Prompts


I gave you a little teaser earlier but there's so much more to zsh's command prompt structure. There's even a built in theming system if you're using oh-my-zsh, allowing you to quickly try out a wide variety of prompts. I modified gnzh to suit my purposes, here's some examples of why it rocks:

+-@Sylvains-MacBook-Pro.local ~

+- cd dev/zsh-battery

+-@Sylvains-MacBook-Pro.local ~/dev/zsh-battery (master*)

+- touch some-file.rb

+-@Sylvains-MacBook-Pro.local ~/dev/zsh-battery (master[?])

+- rm some-file.rb

+-@Sylvains-MacBook-Pro.local ~/dev/zsh-battery (master*)

+-


Unfortunately I can't show you the color changes (aside from the snippet appearing in this piece's featured image), but I can note the key take aways. For example, my command prompt changes to green when I'm in a git project and displays the branch I'm working with. If my working directory isn't clean, then the green * after the branch name turns into a red [?] until I've committed or cleaned up my working directory.

Tab Completion...For Anything


Perhaps the most impressive part of zsh is how many plugins are available to support context aware tab completion. The git plugin is an awesome example. Start typing git check and hit tab, you'll get checkout. Then start typing a branch (or remote!) name and it will tab complete from the available options! This allows me to write very descriptive branch names like fix_admin_invisibility_bug without paying the penalty of typing that out each time I'm going to work on the branch.

Have you found an even better way to utilize zsh in your day-to-day? Leave a comment and let me know!

Published by Sylvain Niles on Monday, October 8, 2012 in Development, Bash, Command Prompts, Development, Zsh.

Sign Up For Your 30 Day Free Trial Today!

You agree to Scripted’s Terms of Use and Privacy Policy.
Already have an account? Login
©2011-2022
Our Company
About Us Privacy Terms of Use GDPR Trust
For Members
Enterprise Agencies Publishers Customer FAQs Newsletter Customer Sign In
For Writers
Writer Services Agreement Writer FAQs Writer Sign In
Additional Resources
The Scripted Blog Industries Podcast Technology Affiliates Competitors
Social Buttons