Links

Banners

How to Customize ZSH

Get Started

I ripped the ZSH config from Manjaro because it's a beautiful config. It has a lot, yes, but you can remove the stuff you know you don't need, which is what I did over time. I finally got all the essentials and no longer depend on carrying around the folders around.

Clean $HOME

To move the location of your config files for ZSH, set the ZDOTDIR environment variable inside of "$HOME"/.zshenv. Add something like export ZDOTDIR=~/.config/zsh.

Note: It'll still look for .zshrc for all your settings.

Configure ZSH

This will wildly depend on a per-person basis. especially the keybindings. I will go over what you may want to set in sequential order because what you set above will affect the stuff below, like the XDG directories.

XDG Directories

XDG Directories are set via environment variables. These allow all compliant programs to know where to look for stuff. For example, config files reside in "$HOME"/.config. Some programs will already look for it, but some may also look for its XDG equivalent, XDG_CONFIG_HOME. Here is a list of what I think to be the most important XDG directories to explicitly set:


				# XDG Dirs
				export XDG_CONFIG_HOME="$HOME"/.config
				export XDG_CACHE_HOME="$HOME"/.cache
				export XDG_DATA_HOME="$HOME"/.local/share
				export XDG_DOCUMENTS_DIR="$HOME"/Documents
				export XDG_DOWNLOAD_DIR="$HOME"/Downloads
				export XDG_MUSIC_DIR="$HOME"/Downloads/Music
				export XDG_VIDEOS_DIR="$HOME"/Downloads/Videos
				export XDG_PICTURES_DIR="$HOME"/Photos
				

I listen to music and I have a script to play music. For the sake of "universality", I set the XDG directory for it, as you can see above. I also use pcmanfm in case I want to drag and drop files, so I also set the XDG directory for my photos folder as well.

Aliases

In the past, I used my rc files in Bash and ZSH to store aliases, but it made the file very long and didn't allow me to use the aliases on multiple shells. The best way to deal with aliases is to store them in their own file and source it like so:


				. "$XDG_CONFIG_HOME"/zsh/aliases
				

This also makes a great transition to the next point.

Set Keybindings

Run cat > /dev/null to allow you to see the escape sequences of your key presses. For me, pressing the right arrow key will display ^[[C and Ctrl+left prints ^[[1;5D.

Inside your .zshrc, make a keybindings section like this:


				# Keybind Section
				bindkey -e
				bindkey '^[[H' beginning-of-line                        # Home
				bindkey "${terminfo[kend]}" end-of-line                 # End
				bindkey '^[[2~' overwrite-mode                          # Insert
				bindkey '^[[3~' delete-char                             # Delete
				bindkey '^[[C'  forward-char                            # Right
				bindkey '^[[D'  backward-char                           # Left
				bindkey '^[[5~' history-beginning-search-backward       # Page up
				bindkey '^[[6~' history-beginning-search-forward        # Page down
				bindkey '^[[1;5C' forward-word                          # Ctrl+Right
				bindkey '^[[1;5D' backward-word                         # Ctrl+Left
				bindkey '^H' backward-kill-word                         # Ctrl+Backspace
				bindkey '^[[Z' undo                                     # Shift+tab
				

Change the contents of this section according to your needs. For more information on keybindings, you may want to visit the Arch Wiki entry.

Essential Plugins

Autocompletion

To have a pleasant experience using the terminal, ZSH's autocompletion plugin is essential. First, install zsh-syntax-highlighting, then source it in your .zshrc. Next, add the following:


				autoload -Uz compinit
				zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'               # Case insensitive tab completion
				zstyle ':completion:*' rehash true                                      # automatically find new executables in path
				zstyle ':completion:*' accept-exact '*(N)'
				zstyle ':completion:*' use-cache on
				zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh/zcompcache	# Where to save command list
				

Command Auto-predictor

Install zsh-history-substring-search and zsh-autosuggestions, then source it in your .zshrc.

Prompt

This is purely aesthetic, but some eye candy will allow you to actually enjoy using something. To get Manjaro's ZSH prompt, include the following:


				# Enables colors
				autoload -Uz colors
				colors
				
				# Set Prompt
				setopt prompt_subst
				PROMPT="%B%{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%u%b >%{$fg[cyan]%}>%B%(?.%{$fg[cyan]%}.%{$fg[red]%})>%{$reset_color%}%b "
				RPROMPT="%{$fg[red]%} %(?..[%?])"
				

Conclusion

This should be enough to give you a good experience using ZSH and it should expose you to what you can do. Happy Computing!

PS: If you just want to rip my config, here it is.