Barbarian Meets Coding

WebDev, UX & a Pinch of Fantasy

4 minutes readzsh

Zsh, Oh-my-zsh and the shell

Zsh is an alternative unix shell to the more common bash.

File system

$ pwd  # print working directory

$ cd .  # go to current directory
$ cd .. # go to parent directory
$ cd -  # go to last directory
$ cd ~  # go to home directory
$ cd    # go to home directory

$ mkdir something # create directory
$ mkdir something/some/thing -p # creates intermediate directories too

Redirecting input and output

Linux programs have built-in support for reading from stdin, producing output to stdout and sending errors to stderr. By default, stdin comes from the keyboard while both stdout and stder are sent to the terminal.

Inputs and outputs can be manipulated using redirection commands:

# > redirects stdout to a file
# This writes the contents of vimrc in file.txt
# It empties the contents of file.txt and overwrites it
cat vimrc > file.txt 

# >> redirects stdout to a file and appends to it
cat vimrc >> file.txt


Pipes allow you to combine linux programs together:

# cat reads the package.json file and sends it to stdout
# the pipe commands takes that and sends it as input to grep
# grep searches for any line that has "author" in it and prints it
cat package.json | grep "author"


The bang ! in linux shells is normally used to refer to previous commands in the command-line history. In zsh you can use it in much the same way with a small difference, ! in zsh are expanded to whatever they refer. This is useful so that you can be more certain of what you’re actually about to execute. For instance, !! normally refers to the last command in your shell history. In zsh if you type !! followed by space or TAB it will be expanded to that last command:

# We type this command
$ ls -al

# Then this one
$ !! 
# TAB and... It expands to the last command executed
$ ls -al

Here are other useful ! commands:

$ !{char} # expands to last command
$ cat hello.txt
$ !c      # expands to the above

$ !! # expands to last command
$ ls -ll
$ !! # expands to the above

$ !$ # expands to the last commands' arguments

Fuzzy Search in the Command line history and file system

Zsh comes with a really great way to interact with you command line history: forward and backward interactive search. Use C-R to search backwards in your command line history and C-S to do the same thing forwards. It has a limitation though, it only shows one single command a time. fzf is a fuzzy finder that integrates with zsh and enhances it in many different ways. One such way is providing amazing support for fuzzy search in you command line history:

Another is providing fuzzy completion for your file system:

To install fzf follow the instructions in the github repository. If you are using MacOS, you can install it using homebrew:

brew install fzf

# To install useful key bindings and fuzzy completion:
$(brew --prefix)/opt/fzf/install

Interesting Zsh Plugins

  • Syntax highlighting: Provides really nice syntax highlighting right within your zsh terminal
  • Autocompletion suggestions: Provides autosuggestions that you can expand with the right arrow or end. It’s fully customizable.
  • Vi mode: Enables vi mode in Zsh, adds a bunch of key bindings and the curent mode to the prompt.

Cool fonts and color schemes for iTerm2

  • iTerm 2 color schemes. Download a color scheme and within iTerm2 go to profile, colors, import colors, select the file with the color scheme and it will become available in the collection of themes.
  • FiraCode. You’ll need to clone the repo and install the font in TrueType (ttf) format in your mac. Then you’ll be able to enable it within iTerm2.

Great companions for Zsh


Jaime González García

Written by Jaime González García , Dad, Husband, Front-end software engineer, UX designer, amateur pixel artist, tinkerer and master of the arcane arts. You should follow him on Twitter where he shares useful stuff! (and is funny too).Jaime González García