Setup ZSH for suggestion, auto completion and text highlighting on linux terminal

Install ZSH, Syntax Highlighting and Auto Suggestions

sudo add-apt-repository universe

sudo apt update

sudo apt install zsh zsh-syntax-highlighting zsh-autosuggestions

zsh

Add syntax-highlighting and autosuggestions to your zshrc file

cp ~/.zshrc ~/.zshrcbackup

echo "source $(dpkg -L zsh-autosuggestions | grep 'zsh$')" | tee -a ~/.zshrc

echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" | tee -a ~/.zshrc

Source your ~/.zshrc file to apply the changes (if you are in bash or another shell, run the zsh command first)

zsh

source ~/.zshrc

Make zsh the default shell

chsh -s $(which zsh)

Now here is a pitfall

Your command history will get cleaned after closing the terminal. So you need to store your commands somewhere to retrieve later.

Open .zshrc file in text editor (for simplicity i've used xed you can use nano/ vim/ code or any other text editor)

xed ~/.zshrc
  1. Add this following lines to ~/.zshrc file
HISTFILE="$HOME/.zsh_history"
HISTSIZE=500000
SAVEHIST=500000
setopt appendhistory
setopt INC_APPEND_HISTORY  
setopt SHARE_HISTORY

Save the file

source your ~/.zshrc file to apply the changes (Repeat Step 4)

source ~/.zshrc

Now all of your command history will save in ~/.zsh_history file.

21