DEV Community

Shawon Saha
Shawon Saha

Posted on

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

zsh

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Make zsh the default shell

chsh -s $(which zsh)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  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
Enter fullscreen mode Exit fullscreen mode

Save the file

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

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

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

Discussion (0)