The Essential Zsh Config for Beginners
Published: 2024-05-27 03:07:43

## Introduction

The shell is an important tool to learning how to configure your computer because it is what controls how you interact with your computer at a fundemental level.
The shell is what you interact with every time you enter a terminal session so it is important to have a base level understanding so that you can become more productive.
I think that learning some basic commands, customizing your shell for what you need and not being afraid to break your system all are apart of sorftware engineering.
I personally have messed some things up on my computer, but gaining problem-solving skills and going through a bootcamp has given me the tools and confidence to know that I can fix any of the problems at hand. So i wanted to give a simple configuration to jumstart you to a beetter quality of life config that should work for everybody.
There are three simple plugins I recommend plus giving youself a theme to look at and some simple aliases to add to your configuration and thats all you need with no panic

## Basic Setup

To start off I personally work with node alot and need this line so I just added it to the top of the file

```
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
```

This is to load NVM to your terminal everytime your terminal starts up. If you ever have a message that nvm doesn't exist when you run the command this with make it availble to you

### Homebrew

Next this is for Macos users to load homebrew into their terminal you can use this code snippet

```
if [[ -f "/opt/homebrew/bin/brew" ]] then
  # If you're using macOS, you'll want this enabled
  eval "$(/opt/homebrew/bin/brew shellenv)"
fi
```

HomeBrew is a package manager to install any programs write from your terminal it is really useful and is essential for any developers.


### Zsh Package Manager

Next we need to load a zsh package manager so that we can load the essential things needed so that we can customize our terminal. There are many package managers you can use and their is a big debate about all of them, I personally use Zinit, but their are plenty you can use like oh-my-zsh, zplug, etc.
All of these are just fine to use with different problems with each, I use zinit because it is very lightweight and allows my terminal to startup fairly quickly.
To startup with zinit you will need to add these lines



```
# Set the directory we want to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"

# Source/Load zinit
source "${ZINIT_HOME}/zinit.zsh"

# Download Zinit, if it's not there yet
if [ ! -d "$ZINIT_HOME" ]; then
   mkdir -p "$(dirname $ZINIT_HOME)"
   git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
```

## Core Plugins

Next I setup some of the core plugins that i think have really helped me the most.
Those would be zsh-syntax-highling, zsh-completions, and zsh-autosuggestions. These three allow me to really know what I'm doing in my terminal and allows me to see old commands that i have run and just re-execute better that using my up arrow in the terminal.

### Zsh-Syntax-Highlighting
It is really a cool plugin it highlights commands when they are actuall commands underlines files when they exist in your current directory and just lets you know when you are actually doing the right thing. This kind of thing is important for a beginner because when you are only looking at a default terminal it is really hard to know what/if you are doing the right thing.

### Zsh-Completions
This plugin is really nice because it allows the terminal to complete command for you so that you don't have to type your whole command out. This plugin ties in really well with zsh-autosuggestions to really allow you to see all that you are doing in the terminal.

### Zsh-autosuggestions
It will read your terminal history and suggest commands to you based on your zsh history and allow you to complete `npm start`, `npm run build`, `npm test`. These may seem simple but when your lazy like me its a big deal.


```
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-syntax-highlighting

# Add in snippets
zinit snippet OMZP::git

# Load completions
autoload -Uz compinit && compinit
```

## Themes

I personally suggest using powerlevel 10k as it has alot of options but their are many terminals online and it  is very hard to cover all of the options out their so i will show how to install powerlevel 10k but it is really up to you on what you like. To install use

```
# Add in Powerlevel10k
zinit ice depth=1; zinit light romkatv/powerlevel10k
```

and when you get into the terminal and type `p10k configure` into your terminal and execute and it will show prompts to guide you to configure your promt how you like it. You may also have to install a nerd font to get this working properly.

## Aliases

These steps are optional but i suggest them for a better expierence. I suggest adding these because the allow you to shorten your syntax when doing anything in your terminal. I like shortening things if you haven't noticed

I also suggest if you use ls to install eza as it gives you a nicer looking ls command with highlighting so you can see clearly which are files vs directories and so on.
to install eza it is `brew install eza`

```
## Everyday Aliases
alias ls="eza --icons=always"
alias cl='clear'

## Git Aliases
alias gad='git add'
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gc='git commit -v'
## Very Nice looking git log graph, imo
alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'"

## Zsh Config Aliases [If you ever want to reconfigure this file use these]
alias zconfig="c ~/.config/zsh/.zshrc"
alias rezsh="source $ZSH_HOME"
```

Don't be intimidated by these steps. Diving into new thing that may seem daunting at first is part of programming but seeing others do it, and realizing the benefits will make it worth it. I know most of you will be like no that's too much I don't want that. It's fine everybody is on their own journey but i promise it is well worth it when you make the jump.