Basic ZSH Setup After New Linux Installation With Oh-My-ZSH

Basic ZSH Setup After New Linux Installation With Oh-My-ZSH

Setup ZSH right after installing linux to use like a pro by executing simple commands

What is ZSH?

The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.

Zsh was created by Paul Falstad in 1990 while he was a student at Princeton University. It combines features from both ksh and tcsh, offering functionality such as programmable command-line completion, extended file globbing, improved variable/array handling, and themeable prompts.

What is Oh-My-ZSH

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes and many more.

Difference between Oh-My-ZSH and ZSH?

Installing ZSH, you are essentially downloading a new program and telling your terminal to use that program (say, instead of bash) to process the commands and run scripts. oh-my-zsh provides a way of managing your zsh configurations, themes and plugins to extend the look and functionality of your shell.

Setup ZSH

  1. Check your default shell.

     echo $0
    

    This will output your default shell in the terminal and it most probably bash on your computer.

  2. Download prerequisites for zsh shell.

     sudo apt install curl git wget -y
    
  3. Now download zsh shell.

     sudo apt install zsh -y
    
  4. Check if zsh is installed in your computer or not.

     zsh
    

    This will change the style in your terminal.

  5. Change Default Shell for your user account.

     chsh -s $(which zsh)
    

    Alternative 3 ways for changing default shell.

  6. Now reboot your linux computer or you can logout and then login into the system also.

  7. Now check shell again.

     echo $0
    

    Now this should show zsh . If it is showing bash again then you may repeat the process carefully again.

  8. Download Oh-My-ZSH

     sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
  9. Download ZSH Auto Suggestion which is a ZSH plugin that suggests commands as you type based on history and completions.

     git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    
  10. Download another ZSH plugin ZSH Syntax Highlighting which provides syntax highlighting for the shell zsh.

    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    
  11. After succesfully passing previous steps, its time to decorate your terminal. Open your .zshrc file with your favourite text editor (nano in my case), probably ~/.zshrc is the file on your computer.

    nano ~/.zshrc
    
  12. Change theme of your ZSH shell. Comment out previous themes line with a # . and add your favourite theme. You may find all your Oh-My-ZSH pre-installed theme in your ~/.oh-my-zsh/themes folder.

    # default theme
    # ZSH_THEME="robbyrussell"
    ZSH_THEME="agnoster"
    
  13. Add your favouriote ZSH plugins (these are in ~/.oh-my-zsh/themes) for convenient usage:
    Install fzf to use zsh-interactive-cd .

    plugins=(
        command-not-found
        copybuffer
        git
        history
        zsh-autosuggestions
        zsh-interactive-cd
        zsh-syntax-highlighting
    )
    
  14. If you have bash aliases in ~/.bash_aliases file then you have to add one more line in ~/.zshrc file

    # Set personal aliases, overriding those provided by oh-my-zsh libs,
    # plugins, and themes. Aliases can be placed here, though oh-my-zsh
    # users are encouraged to define aliases within the ZSH_CUSTOM folder.
    # For a full list of active aliases, run `alias`.
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    fi
    # Example aliases
    # alias zshconfig="mate ~/.zshrc"
    # alias ohmyzsh="mate ~/.oh-my-zsh"
    
  15. You have to add this before the line: source $ZSH/oh-my-zsh.sh

  16. Run the command to see changes:

    exec zsh
    
  17. If you are seeing broken style in your terminal then you have to download and install a powerline font such as Fira Font, Hack Font etc.

  18. (Optional) If you want to explore more style then you may try Power Level 10k Theme:

    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
    echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
    
  19. (If you chose 18) Go to powerlevel10k folder & run this to customize style

    p10k configure
    
  20. Further know about powerlevel 10k on this link.

References