Logo

dev-resources.site

for different kinds of informations.

A Guide to Setting Up Zsh: Improving Your Terminal Experience

Published at
10/28/2024
Categories
terminal
cli
zsh
omz
Author
jamesjf7
Categories
4 categories in total
terminal
open
cli
open
zsh
open
omz
open
Author
8 person written this
jamesjf7
open
A Guide to Setting Up Zsh: Improving Your Terminal Experience

Hello. This is a guide I've put together mainly as a reference for myself when setting up a new Ubuntu device. I often forget the exact steps, so having this written down helps me replicate my preferred terminal setup. I'm sharing it in case others find it useful too. This guide covers setting up Zsh with some add-ons that I find helpful.

What We're Setting Up

  1. Zsh: An improved version of the standard command-line interface.
  2. Oh My Zsh: A collection of helpful features for Zsh.
  3. Powerlevel10k: A theme that makes your command line look... nice.
  4. Autosuggestions: A feature that suggests commands as you type.

Step 1: Install Zsh

First, we need to install Zsh. The process is usually straightforward, but it might vary depending on your operating system.

For Mac users:

If you're using a recent version of macOS, Zsh is already installed. You can move on to Step 2.

For Ubuntu or other Debian-based Linux:

Open your terminal and type these commands:

sudo apt update
sudo apt install zsh
Enter fullscreen mode Exit fullscreen mode

You'll need to enter your password and confirm the installation.

For other operating systems:

You might need to look up specific instructions for your system. Try searching for "How to install Zsh on [Your Operating System]".

Step 2: Install Oh My Zsh

Now that we have Zsh, let's add Oh My Zsh. Copy and paste this command into your terminal:

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

This command downloads and runs the Oh My Zsh installer. Just follow any prompts that appear.

Step 3: Install the Powerlevel10k Theme

Powerlevel10k will change how your terminal looks. Here's how to set it up:

  1. Use this command to download Powerlevel10k:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Enter fullscreen mode Exit fullscreen mode
  1. We need to edit a file called .zshrc. Open it with this command:
nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  1. Find the line that starts with ZSH_THEME. Change it to:
ZSH_THEME="powerlevel10k/powerlevel10k"
Enter fullscreen mode Exit fullscreen mode
  1. To save and exit, press Ctrl+X, then Y, then Enter.

Step 4: Add Autosuggestions

Autosuggestions can help you type commands faster. Here's how to add this feature:

  1. Run this command to download the autosuggestions plugin:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Enter fullscreen mode Exit fullscreen mode
  1. We need to edit the .zshrc file again:
nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  1. Find the line that starts with plugins=. Add zsh-autosuggestions to the list. It should look something like this:
plugins=(git zsh-autosuggestions)
Enter fullscreen mode Exit fullscreen mode
  1. Save and exit (Ctrl+X, Y, Enter).

Step 5: Set Up Powerlevel10k

Now we'll customize how your terminal looks.

  1. Close your terminal completely and open a new one.

  2. You should see a setup wizard for Powerlevel10k. If you don't, type p10k configure and press Enter.

  3. Follow the prompts to choose how you want your terminal to look. You can always change this later by running p10k configure again.

Step 6: Using Your New Setup

That's it. You've set up a more advanced terminal. Here are some things to note:

  • To use autosuggestions, start typing a command you've used before. You should see a faded suggestion appear. Press the right arrow key to accept it.
  • You can explore more Oh My Zsh plugins on the official wiki.
  • If something doesn't seem right, try closing your terminal and opening a new one.

It's okay if you don't understand everything right away. You'll get more comfortable with it as you use it.

Example .zshrc File

After setting everything up, your .zshrc file will contain all the configurations we've discussed. I've put my personal .zshrc file on GitHub if you want to look at it:

[Link to your GitHub repository with the .zshrc file]

Here's a brief explanation of what you might see in this file:

  1. Oh My Zsh Path:
   export ZSH="$HOME/.oh-my-zsh"
Enter fullscreen mode Exit fullscreen mode
  1. Theme Setting:
   ZSH_THEME="powerlevel10k/powerlevel10k"
Enter fullscreen mode Exit fullscreen mode
  1. Plugins:
   plugins=(git zsh-autosuggestions)
Enter fullscreen mode Exit fullscreen mode
  1. Oh My Zsh Source:
   source $ZSH/oh-my-zsh.sh
Enter fullscreen mode Exit fullscreen mode
  1. Powerlevel10k Customizations: Lines starting with POWERLEVEL9K_ or POWERLEVEL10K_.

  2. Custom Aliases: Lines starting with alias.

You can look at my .zshrc file here for ideas, but remember that your file should be set up for your own needs and preferences.

If you make changes to your .zshrc file, you'll need to either restart your terminal or run source ~/.zshrc for the changes to take effect.

Conclusion

Now we've set up a more advanced terminal environment. With Zsh, Oh My Zsh, Powerlevel10k, and autosuggestions. Feel free to experiment with your configuration as you become more comfortable with it. I hope you find this setup helpful for your work.

zsh Article's
30 articles in total
Favicon
Understanding Linux Shells: Interactive, Non-Interactive, and RC Files
Favicon
Enhance Your macOS Terminal with Oh My Zsh, Autosuggestions, and Powerlevel10k
Favicon
Oh My Zsh: A Simple Guide for Developers
Favicon
Display Dir Structure in Tree Format.
Favicon
A Guide to Setting Up Zsh: Improving Your Terminal Experience
Favicon
OMZ: Some Plugins that I forget about
Favicon
Managing dotfiles using GNU Stow on macOS
Favicon
Copy paste bash command but dont understand what it does?
Favicon
How do I show the git branch with colours in Bash prompt?
Favicon
Demystifying Bash and Zsh on Mac
Favicon
How to make your terminal looks Splendid
Favicon
Adding Zsh Completion for `gh copilot`
Favicon
Docker aliases with zsh using Ohmyzsh
Favicon
Improve your PowerShell experience
Favicon
Colorful terminals with Oh My Posh and Windows Terminal
Favicon
Some Config Ideas for your ZSH
Favicon
Ma configuration post-installation d'Arch Linux
Favicon
πŸš€ Simplify Your Linux Process Killing with a Fuzzy Process Killer πŸš€
Favicon
How to Remove Duplicate Paths in ZSH on MacOS
Favicon
zsh: permission denied: ./gradlew
Favicon
How to install oh-my-zsh and zsh-autosuggestions for macbook
Favicon
Add Visual Studio Code to your OSX zsh PATH
Favicon
Simple Directory Watcher to Restart Dev Server
Favicon
πŸš€ Um Guia PrΓ‘tico para Configurar Zsh, Oh My Zsh, asdf e Spaceship Prompt com Zinit para Seu Ambiente de Desenvolvimento
Favicon
πŸš€ A hands-on guide to setting up zsh, oh my zsh, asdf, and spaceship prompt with zinit for your development environment
Favicon
My zsh config
Favicon
Finding Terminal Utopia
Favicon
How to stop Storybook opening a new webpage on start (automatically with zsh)
Favicon
zoxide - A faster alternative to boring cd command
Favicon
A quick bash/zsh tip

Featured ones: