Looking for a specific post? Checkout the Blog Index.

By Kimserey Lam with

Zsh Plugins

Nov 15th, 2019 - written by Kimserey with .

Last week we looked into how we could install iTerm2 combined with Oh My Zsh to create the best possible terminal experience. Today we’ll have a look at the plugins that we can install to make our terminal even more powerful!

Default Plugins

Oh My Zsh comes with a set of plugins. The list can be found on the official Github repository.

Those that I currently find useful for my workflow:

1
2
3
4
5
plugins=(
  colorize
  colored-man-pages
  fasd
)

colorize

colorize will provide a ccat command which colorize cat with default pygments settings:

1
ccat app.py

colored-man-pages

colored-man-pages will colorize the man page which makes reading nicer:

1
man ls

fasd

fasd will provide a fast access directory with z, and other shortcut but I see myself using z the most often, which is an alias to Jump to the most used directory matching the string. The aliases used by fasd are the following:

1
2
3
4
5
6
7
8
alias a='fasd -a'        # any
alias s='fasd -si'       # show / search / select
alias d='fasd -d'        # directory
alias f='fasd -f'        # file
alias sd='fasd -sid'     # interactive directory selection
alias sf='fasd -sif'     # interactive file selection
alias z='fasd_cd -d'     # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection

For example,

1
z my-project

will jump top my-project, regardless of the path, if we navigated to it before. Even shorter,

1
z my-p

should also jumnp to the my-project.

fasd also provide a shortcut to resolve paths with , (comma).

1
mv ,my-p

Pressing tab will autosuggests all possible full paths including **/*my-p*. Useful for commands like mv where we want to resolve two paths.

Autosuggestions

Other than preinstalled plugins, we can also get out of the box plguins like autosuggestions which provide an autosuggestion of command based on the first input characters. To install it we clone the repository into the custom plugins folder:

1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Then we simply add it to the list of plugins:

1
2
3
4
plugins=(
  ...,
  zsh-autosuggestions
)

We should now have an autosuggestion!

Syntax Highlighting

Similarly to autosuggestion, we can install syntax highlighting plugins which will provide color on the command we write. We clone the repository into the custom plugins:

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

And we add it to the list of plugins:

1
2
3
4
plugins=(
  ...,
  zsh-syntax-highlighting
)

And our commands should now be colored!

iTerm2 Utilities

Sort of a sidenote to zsh, iterm2 also comes with some nice plugins which can be downloaded via the menu:

1
iTerm2 > Install Shell Integration

The files get downloaded under /.iterm2 which we can then add to zsh path:

1
export PATH=$HOME/.iterm2:$PATH

This then give us the useful commands it2copy, imgcat and imgls.

it2copy

it2copy which can be piped to copy content:

1
cat myfile.txt | it2copy

Clipboard permission must be granted:

1
Preferences > General > Services (tick "Application in terminal may access clipboard")

imgcat

imgcat is another great command which display an image within the terminal.

1
imgcat me.png

imgls

Lastly imgls would list images within a folder.

1
imgls ./*

Conclusion

Today we looked into some nice plugins which come together with Oh My Zsh. We started by looking at the default plugins, like colorize and fasd. Then we moved on to look at plugins being maintain outside of Oh My Zsh like autosuggestions and syntax highlighting. And we completed this post by looking at some utilities from iTerm2 which can be installed separately. I hope you liked this post and I see you on the next one!

External Sources

Designed, built and maintained by Kimserey Lam.