Five ZSH tricks to optimize your shell workflow

Below on the video I’ll demonstrate five handy tricks you can do with zsh shell. zsh is a powerful command line shell for UNIX operating systems (Linux, Ubuntu, OSX, etc.) Newcomer shell users may find these tips helpful.

You want to use zsh because it make you type less, find command faster and ultimately make you more productive when working with UNIX and servers.

The tips are based on our tuned ztanesh shell scripts which you may wan to install too 🙂

1) Navigate around on the file system using zsh “menu select” tab completion. Writing a path to the command line equals to cd‘ing that directory in zsh. What we do here is that we open the tab completion in the current folder using the dot slash notation and then find our way to the target folder. The menu select constructs the path for us. Instructions how to set up zsh’s menu select for this.

2) Back to the previous folder where you were: cd –. Handy when you jump around in the directory tree when working. You can type only cd to go to the home folder. .. (even without cd) takes you one level higher, … two lever higher and so on.

3) Move a file using the menu select completion as shown in the first trick. You can open menu completion for any command or target.

4) zsh has superior tab completion compared to other shells: here I autocomplete an SSH host and use the menu selector to choose it from the list. zsh can also complete scp copy remote filenames. Other example is kill command where the tab completion allows you to choose the target process in a menu.

5) CTRL+R for the history search. Type CTRL + R and few letters of any of your previous commands and CTRL+R again to find it up (incremental search with history-incremental-pattern-search-backward). No need to navigate through the long backlog using up arrow. I don’t know how I managed to live 15 years without getting this to my muscle memory.

Also on the video you can see how the terminal tab colorization by the current (ssh‘ed) server works.

For more useful keybindings on OSX / iTerm 2, see how to bind ALT + arrow to move between words and fn + arrow to move to the beginning and the end of the line.

More tips welcome. Especially I am interested in

  • Fuzzy / partial string match for the history earch (Sublime Text 2 CTRL+T style go to anywhere)
  • Menu select for the history search

 

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

5 thoughts on “Five ZSH tricks to optimize your shell workflow

  1. Hey, I’m a community blog curator for DZone. I wanted to talk with you about potentially featuring your blog on DZone’s content portals. Send me an email at allenc [at] dzone [dot] com and I’ll explain the details.

  2. For fuzzy find, fzf works great (and “$(fzf)” works even better inline), but zsh allows us to use globs to find files recursively, so
    vim /var/www/**/index.php
    would open every file named index.php that resides under the /var/www directory. You can even use tab completion to “preview” the command before you run it. Try it, it works great!

Leave a Reply

Your email address will not be published. Required fields are marked *