Ubuntu-Server
Setting up Zsh

Certainly! Here’s a detailed procedural guide that includes the steps to be performed within a zsh shell, including GitHub commands and any additional setup.


Setting Up Zsh with Oh My Zsh, Plugins, and Custom Theme

1. Update Package Lists

  1. Open your terminal.
  2. Run the following command to update your package lists:
    sudo apt update

2. Install Zsh

  1. Install zsh using the following command:
    sudo apt install -y zsh

3. Install Oh My Zsh

  1. Install Oh My Zsh, a framework for managing zsh configuration:
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

4. Install Zsh Plugins

  1. Open a new zsh session to perform the following commands.

  2. Clone zsh-syntax-highlighting Plugin:

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

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

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

5. Update .zshrc Configuration

  1. Add Plugins to .zshrc:

    • Run the following command to add plugins to your .zshrc file:
      sed -i '/^plugins=(/c\plugins=(git zsh-syntax-highlighting zsh-autosuggestions zsh-completions)' ~/.zshrc
  2. Set Custom Prompt:

    • Update the PROMPT variable in .zshrc:
      sed -i '/^PROMPT=/c\PROMPT="%n@%m %~ %# "' ~/.zshrc

6. Create and Apply Custom Theme

  1. Define and Create Custom Theme:

    • Create a new theme file with colors:
      THEME_NAME="username-host-colored"
      mkdir -p ~/.oh-my-zsh/custom/themes
      cat <<EOF > ~/.oh-my-zsh/custom/themes/$THEME_NAME.zsh-theme
      # Define colors
      autoload -U colors && colors
       
      # Custom prompt
      PROMPT='%F{green}%n%f@%F{cyan}%m%f %F{yellow}%~%f %# '
      EOF
  2. Update .zshrc to Use Custom Theme:

    • Set the theme in .zshrc:
      sed -i "s/^ZSH_THEME=.*/ZSH_THEME=\"$THEME_NAME\"/" ~/.zshrc

7. Apply Changes

  1. Source .zshrc:
    • Apply the changes made to .zshrc:
      source ~/.zshrc

8. (Optional) Set Zsh as Default Shell

  1. Change Default Shell to Zsh:
    • Set zsh as your default shell:
      chsh -s $(which zsh)

9. Additional Setup in Zsh

  1. Verify Plugin Installation:

    • Open a new zsh session or source the .zshrc file again:
      source ~/.zshrc
    • Check if the plugins are working by testing their functionality (e.g., syntax highlighting, auto-suggestions).
  2. Update Plugin Repositories (Optional):

    • To update the plugins from their repositories, run the following commands:
      cd ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
      git pull
      cd ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
      git pull
      cd ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
      git pull

By following these steps, you’ll have zsh installed, configured with Oh My Zsh, plugins, a custom colored prompt, and any additional setup needed for the plugins.