Don't Bash it Till You've Tried it! - Why Switch to Zsh?

 Zsh prompt

With the announcement that Kali Linux will be switching to using Zsh as it's default shell in its next release (2020.4), I thought I'd outline some of the features of Zsh that persuaded me to switch from Bash a while ago.

Zsh is an extension of the Bourne Shell (sh) with a multitude of useful features. This post will focus on specific features of Zsh that I find useful; if you want a quick intro to Zsh and how to switch to it, give this article by How-To Geek a read.

Oh My Zsh


Oh My Zsh is an open source framework that makes customising your Zsh configuration easy. I've already covered how to install Oh My Zsh in a previous post so give that a read, or head over to the Oh My Zsh website to get started.

Once you have Oh My Zsh installed, it becomes easy to add plugins and themes to your Zsh configuration.

Themes


Themes are a great way to customise the look and feel of your terminal. Oh My Zsh comes with some default themes which give a good overview of what can be accomplished by using a Zsh theme. However, if none of these suit you, you can find many more on GitHub in repositories such as the awesome-zsh-plugins repository, or you can even make your own! I've covered writing custom Zsh themes in a previous post, so do give that a read if this interests you.

Personally, I use a custom theme called "Icicle" (pictured in the image at the top of this post), which can be downloaded from my GitHub here.

Plugins


Plugins are tools designed to make your day-to-day use of the terminal easier and range from sets of preconfigured aliases, to simple scripts that automate common tasks. Oh My Zsh includes a collection of default plugins which includes the following plugins that I use in my own Zsh configuration:
  • catimg: Displays images in your terminal (like the cat command but for pictures)
  • copydir: Copies the current working directory to the clipboard
  • copyfile: Copies the contents of a file to the clipboard
  • encode64: Provides aliases for easily encoding and decoding data using base64
  • wd: Provides a way of changing to custom directories without needing to type out their full path
  • web-search: Provides aliases for searching popular search engines from the terminal
I also recommend the zsh-autosuggestions plugin (not included with Oh My Zsh) which suggests commands as you type based on your command history.

Aliases


Much like Bash, Zsh allows users to create aliases which can save you from regularly having to type out the same long commands. These can be defined in your .zshrc file in the same way that you would define them in Bash.

Aliases can be useful when you often run tools with long file paths. For example, I have the following alias configured for my GTFOBLookup tool:

alias gtfobl='python3 /home/consultant/Pentest/General/GTFOBLookup/gtfoblookup.py'

They are also useful for grouping a long sequence of commands into a single command. For example, the following alias will produce a list of live IP addresses based on an ARP scan of the local network:

alias livefromarp='sudo arp-scan -l | tail -n +3 | head -n -3 | cut -f1'

Smart Tab Completion


Unlike in Bash, Zsh's tab completion is smart and will only suggest items it believes are compatible with the current command. For example, when using tab completion with the cd command, Zsh will only display directories as it knows you cannot cd to a file.

Furthermore, Zsh's tab completion works with command switches, allowing you to look up switches in the middle of typing a command instead of having to use the --help option first as shown below:


Zsh smart tab completion

Conclusion


Zsh incorporates a multitude of useful features beyond those discussed in this post, however, I wanted to focus on the features that I find to be the most useful and use most often.


I highly recommend switching to Zsh as, whilst it can take a little getting used to, it can make your life easier and boost your productivity at the same time.

No comments:

Post a Comment

Popular Posts