Skip to content

Z Shell (zsh)

The Z Shell (zsh) is a powerful and extensible shell for Unix systems. It offers numerous improvements over the standard Bash shell, including better autocompletion, advanced globbing features, and a flexible plugin system.

Installation

  1. zsh is installed using the package manager

    sudo apt update
    sudo apt install zsh
    

  2. zsh is set as the default shell

    chsh -s $(which zsh)
    

  3. Oh My Zsh is installed (optional, but recommended)

    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    

Basic Configuration

  1. A .zshrc file is created in the home directory

    touch ~/.zshrc
    

  2. Basic configurations are added

    # Autocompletion is enabled
    autoload -U compinit
    compinit
    
    # The prompt is set
    PROMPT='%n@%m:%~%# '
    
    # Color support is enabled
    autoload -U colors && colors
    

Advanced Features

  • Autocompletion: Intelligent command, file, and option completion
  • Globbing: Advanced pattern matching for filenames
  • Plugin System: Easy integration of extensions
  • Themes: Customizable shell themes
  • Aliases: Custom command shortcuts

Useful Plugins

  1. zsh-autosuggestions: Suggestions based on command history

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

  2. zsh-syntax-highlighting: Syntax highlighting for commands

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

  3. zsh-completions: Additional completions

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

Tips and Tricks

  • setopt is used to enable zsh options
  • alias is used for frequently used commands
  • The prompt is configured with PROMPT or RPROMPT
  • history is used to access command history
  • setopt share_history is enabled for shared command history between terminals

Troubleshooting

If issues are encountered, the following steps are taken:

  1. The .zshrc file is checked for syntax errors
  2. The configuration is tested with zsh -x
  3. Permissions of configuration files are verified
  4. The zsh documentation is consulted for additional help