Skip to content

Creating a Custom Shell

Customizing Zsh

Customizing my shell significantly enhanced my productivity, made my workflow more efficient and made content more readable. With a tailored shell environment, you can streamline tasks, reduce repetitive actions, and access powerful features that improve your overall user experience. In this walkthrough, I'll be going through the steps I took to set up a customized Zsh shell using zinit as the plugin manager.

chacho-shell

1. Install zsh

If you don't already have zsh installed, you can install it using your package manager.

macOS, use Homebrew:

brew install zsh

Ubuntu/Debian:

sudo apt install zsh autojump git

2. Set zsh as the Default Shell

Set zsh as default shell:

chsh -s $(which zsh)

3. Install zinit

zinit is a plugin manager for zsh that makes it easy to manage and load plugins.

Download and install zinit:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma-continuum/zinit/main/scripts/install.sh)"

4. Configure zsh with zinit and Oh My zsh

Create or edit your .zshrc file to configure zinit and load Oh My zsh:

vi ~/.zshrc
Add content to the file:
# Load zinit
source ~/.zinit/bin/zinit.zsh

#  On a Linux box, you won't need this next line, but if you're on macOS, you may need to source autojump so you can uncomment this: 
# [[ -s /opt/homebrew/etc/profile.d/autojump.sh ]] && source /opt/homebrew/etc/profile.d/autojump.sh

# Load Oh My zsh
zinit light ohmyzsh/ohmyzsh

# Load the theme
zinit light romkatv/powerlevel10k

# Load plugins
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light hcgraf/zsh-sudo
zinit light wting/autojump
zinit light ael-code/zsh-colored-man-pages

Plugins Explanations

These plugins were chosen based on my particular needs/uses, but you could add/drop any based on what you want. Here's what each of these ones do:
- zsh-users/zsh-autosuggestions: Suggests commands based on history as you type.
- zsh-users/zsh-syntax-highlighting: Provides syntax highlighting for commands.
- zsh-users/zsh-completions: Adds additional command completions for zsh.
- hcgraf/zsh-sudo: Automatically prepends sudo to the previous command.
- autojump: Allows quick navigation to frequently used directories.
- ael-code/zsh-colored-man-pages: Adds color to man pages for better readability.

5. Install Powerlevel10k

Powerlevel10k is a popular theme for zsh that provides a highly customizable and informative prompt. It should already be installed with the above configuration, but you can follow these steps to ensure it's set up correctly:

# If not already cloned, clone the repository
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

6. Apply and Test Your Configuration

zsh
source ~/.zshrc

7. Install Some Fonts

git clone https://github.com/ryanoasis/nerd-fonts.git --depth=1
cd nerd-fonts
./install.sh

cd .. && rm -rf nerd-fonts

8. Configure Powerlevel10k

Run the Powerlevel10k configuration wizard to customize your prompt:

p10k configure
Follow the prompts to set up your preferred style and information display.

9. Building a Customization

If a customization you want is not available, you can build it as this step by step explains for colorizing the cat command's output. NOTE: This example ccat is available for install using brew or apt, but provides an example of how you might go about installing when it is not available through your native package manager.

First make sure go is installed.

sudo apt install golang-go

go install github.com/owenthereal/ccat@latest

cd ~/go/bin/ && ls
If ccat is displayed, you're good to test it to make sure it does what you want:
./ccat /etc/passwd
And now you can move it into the directory so that it will be executable as ccat rather than having to cd into the location and run it as ./ccat
cp ~/go/bin/ccat /usr/bin
Note: If you are using macOS, you'll likely need to move it to the local version since /usr/bin is locked down:
cp ~/go/bin/ccat /usr/local/bin

10. Customizing Further

If you want to further customize your zsh setup, you can:

  • Edit the .p10k.zsh file generated by the Powerlevel10k configuration wizard for more advanced customization.
  • Explore additional Oh My zsh plugins and themes available at the Oh My zsh GitHub repository.

Set Zsh Options

Additional Options can also be added to your .zshrc file. For example:

# Set zsh options
setopt AUTO_CD
setopt APPEND_HISTORY
setopt HIST_IGNORE_DUPS
setopt SHARE_HISTORY

# Aliases
alias ll='ls -lah'
alias gs='git status'
alias gp='git pull'
alias gd='git diff'
alias gc='git commit'
alias cat='ccat --bg=dark'
The setopt commands enable specific options in Zsh, which alter its behavior in useful ways.

  • setopt AUTO_CD: Automatically changes the directory when you type the name of a directory without cd. For example, typing Documents instead of cd Documents.
  • setopt APPEND_HISTORY: Appends new commands to the history file instead of overwriting it. This ensures that your command history persists across sessions.
  • setopt HIST_IGNORE_DUPS: Prevents the history list from recording duplicate commands. This helps keep the history clean by only storing unique commands.
  • setopt SHARE_HISTORY: Shares the command history across all running Zsh sessions. Commands entered in one terminal session will be immediately available in another.

Aliases

Aliases are shortcuts for longer commands, making them quicker and easier to type.

  • alias ll='ls -lah': Defines ll as an alias for ls -lah, which lists files in the current directory with detailed information (including hidden files) in a human-readable format.
  • alias gs='git status': Defines gs as an alias for git status, which shows the current status of the Git repository.
  • alias gp='git pull': Defines gp as an alias for git pull, which fetches and merges changes from a remote repository to your local repository.
  • alias gd='git diff': Defines gd as an alias for git diff, which shows the differences between the working directory and the index or between two commits.
  • alias gc='git commit': Defines gc as an alias for git commit, which creates a new commit containing the current contents of the index.

Conclusion

Customizing your shell with zsh and zinit allows you to create a powerful and efficient working environment tailored to your needs. By leveraging plugins, themes, and custom configurations, you can enhance your productivity, streamline your workflows, and enjoy a more personalized computing experience. Whether you're a developer, sysadmin, or just a power user, a customized shell setup can make a significant difference in your daily tasks.