zsh

How to Use ZSH Auto-suggestions

ZSH is a popular Unix shell that extends the Bourne Again Shell. It comes packed with features and improvements over Bash. If you are a regular terminal user, having an exceptional terminal session will improve your workflow and help you enjoy using the terminal.

This tutorial will teach you how to set up a ZSH shell and add features, such as command auto-suggestions.

Step 1 – Installing ZSH

The first step before adding shell extensions is to ensure you have ZSH. It is available in most major Linux distributions package managers.

To install it, use the following commands:

# Debian
sudo apt-get install zsh
#Fedora
sudo yum install zsh
# Arch
sudo pacman -S zsh

Once you have ZSH installed successfully, we can proceed to install the zsh-autosuggestions tool.

Step 2 – Changing Default Shell

After installing ZSH, it is good to make sure it is the default shell. This will prevent you from launching the ZSH shell when using your tool.

chsh -s $(which zsh)

To confirm, enter the following command:

which $SHELL
/usr/bin/zsh

Step 3 – Enabling zsh-autosuggestions

After installing and setting up the ZSH shell, we can set up the zsh-autosuggestions plugin. Start by cloning the zsh-autosuggestions:

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

Finally, add the following command to your .zshrc file:

source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

Using Oh-my-ZSH Framework

If you have the oh-my-zsh framework installed, you can use the auto-suggestions as a plugin. Start cloning the auto-suggestions repository using the following command:

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

Next, enable the plugin by adding the entry as shown below:

plugins=( zsh-autosuggestions)

Import Bash History to ZSH

If you were using Bash as your default shell, you could import all your command history from the .bash_history file.

Consider the following link.

Conclusion

In this tutorial, we discussed how to set up a ZSH shell and the zsh-autosuggestions feature. It automatically provides suggestions for commands based on previous commands. Thus, making it easier for recurring commands.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list