Everybody loves Zsh. And most, if not every tutorial teaches to use Oh my Zsh (OMZ) to manage its plugins.
But the truth is, Zsh does not need a plugin manager. OMZ makes my terminal really slow, it takes a whole minute to load sometimes. Waiting that much time to type a command makes my life miserable.
So, what's the alternative?
We can manually tell zsh to load our plugins.
It is as simple as just adding this line at ~/.zshrc:
source path/to/your/custom/plugin
IT IS DONE!
I'll, however, give you a full guide to add a theme and plugins.
Adding spaceship theme to Zsh... and some plugins
We are going to install the following plugins into Zsh:
Step 1: Back-up
First we need to make a copy of our current .zshrc.
~ cp .zshrc .zshrc_backup
Done!
Step 2: Creating a directory for our zsh files
I chose .zsh for the directory name, you can name it however you'd like.
~ mkdir -p .zsh/plugins .zsh/themes
~ touch .zsh/.zshrc
I like to save my .zshrc file inside a .zsh directory and then link it to ~, but you may do as you please.
Now we add this line to our new ~/.zsh/.zshrc
### ZSH HOME
export ZSH=$HOME/.zsh
Step 3: History
OMZ sets your history file automatically, but we need to create it ourselves.
If you are migrating from OMZ:
~ mv .zsh_history .zsh/
If you are making everything from scratch:
~ touch .zsh/.zsh_history
Now we open our ~/.zsh/.zshrc and add the following lines:
### ZSH HOME
export ZSH=$HOME/.zsh
### ---- history config -------------------------------------
export HISTFILE=$ZSH/.zsh_history
# How many commands zsh will load to memory.
export HISTSIZE=10000
# How many commands history will save on file.
export SAVEHIST=10000
# History won't save duplicates.
setopt HIST_IGNORE_ALL_DUPS
# History won't show duplicates on search.
setopt HIST_FIND_NO_DUPS
Step 4: PATH
This is the most important step, because if you mess it up you will break your shell.
My shell is different then yours, so you have to copy it from your old .zshrc or the .zshrc_backup we have created.
It looks like this:
export PATH=$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH
yours might be slightly different.
Add it to the new .zshrc file.
Your file will be like this:
### PATH - DONT COPY MY PATH - COPY YOUR OWN
export PATH=$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH
### ZSH HOME
export ZSH=$HOME/.zsh
### ---- history config -------------------------------------
export HISTFILE=$ZSH/.zsh_history
# How many commands zsh will load to memory.
export HISTSIZE=10000
# How many commands history will save on file.
export SAVEHIST=10000
# History won't save duplicates.
setopt HIST_IGNORE_ALL_DUPS
# History won't show duplicates on search.
setopt HIST_FIND_NO_DUPS
Step 5: Spaceship
We are going to clone the theme from github.
First we get inside our themes folder:
~ cd .zsh/themes
Then we clone the theme:
git clone git@github.com:spaceship-prompt/spaceship-prompt.git
Now we just tell zsh to use our new theme.
source $ZSH/themes/spaceship-prompt/spaceship.zsh-theme
You can configure the theme the way you want. Just go to the Github repository and read the instructions
These are my configurations:
SPACESHIP_PROMPT_ORDER=(
user # Username section
dir # Current directory section
host # Hostname section
git # Git section (git_branch + git_status)
hg # Mercurial section (hg_branch + hg_status)
exec_time # Execution time
line_sep # Line break
vi_mode # Vi-mode indicator
jobs # Background jobs indicator
exit_code # Exit code section
char # Prompt character
)
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "
.zshrc:
### PATH - DONT COPY MY PATH - COPY YOUR OWN
export PATH=$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH
### ZSH HOME
export ZSH=$HOME/.zsh
### ---- history config -------------------------------------
export HISTFILE=$ZSH/.zsh_history
# How many commands zsh will load to memory.
export HISTSIZE=10000
# How many commands history will save on file.
export SAVEHIST=10000
# History won't save duplicates.
setopt HIST_IGNORE_ALL_DUPS
# History won't show duplicates on search.
setopt HIST_FIND_NO_DUPS
### ---- PLUGINS & THEMES -----------------------------------
source $ZSH/themes/spaceship-prompt/spaceship.zsh-theme
### --- Spaceship Config ------------------------------------
SPACESHIP_PROMPT_ORDER=(
user # Username section
dir # Current directory section
host # Hostname section
git # Git section (git_branch + git_status)
hg # Mercurial section (hg_branch + hg_status)
exec_time # Execution time
line_sep # Line break
vi_mode # Vi-mode indicator
jobs # Background jobs indicator
exit_code # Exit code section
char # Prompt character
)
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "
Step 6: Plugins:
Same as the theme, we clone the plugins from github.
Get inside plugins directory:
~ cd .zsh/plugins
Clone the plugins:
~/.zsh/plugins: git clone git@github.com:zdharma-zmirror/fast-syntax-highlighting.git
~/.zsh/plugins: git clone git@github.com:zsh-users/zsh-autosuggestions.git
~/.zsh/plugins: git clone git@github.com:zsh-users/zsh-completions.git
Now we just source them inside .zshrc
Fast-Syntax-Highlighting:
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
ZSH-AutoSuggestions:
source $ZSH/plugins/zsh-autosuggestions-master/zsh-autosuggestions.zsh
ZSH Completions:
This is different, but not too complicated.
Add this line to .zshrc:
fpath=($ZSH/plugins/zsh-completions/src $fpath)
The official instructtions say we might need to execute this command:
rm -f ~/.zcompdump; compinit
I did not need to execute it.
All right, we have done it!
Our .zshrc file ends like this:
### PATH - DONT COPY MY PATH - COPY YOUR OWN
export PATH=$HOME/bin:/usr/local/bin:/snap/bin:/opt/bin:$PATH
### ZSH HOME
export ZSH=$HOME/.zsh
### ---- history config -------------------------------------
export HISTFILE=$ZSH/.zsh_history
# How many commands zsh will load to memory.
export HISTSIZE=10000
# How many commands history will save on file.
export SAVEHIST=10000
# History won't save duplicates.
setopt HIST_IGNORE_ALL_DUPS
# History won't show duplicates on search.
setopt HIST_FIND_NO_DUPS
### ---- PLUGINS & THEMES -----------------------------------
source $ZSH/themes/spaceship-prompt/spaceship.zsh-theme
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source $ZSH/plugins/zsh-autosuggestions-master/zsh-autosuggestions.zsh
fpath=($ZSH/plugins/zsh-completions/src $fpath)
### --- Spaceship Config ------------------------------------
SPACESHIP_PROMPT_ORDER=(
user # Username section
dir # Current directory section
host # Hostname section
git # Git section (git_branch + git_status)
hg # Mercurial section (hg_branch + hg_status)
exec_time # Execution time
line_sep # Line break
vi_mode # Vi-mode indicator
jobs # Background jobs indicator
exit_code # Exit code section
char # Prompt character
)
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "
Step 7: Change the old .zshrc to the new.
First we exclude the old one (keep the backup):
~ rm .zshrc
Then link the new one to home:
~ ln -s -T .zsh/.zshrc .zshrc
Finally we source the new .zshrc:
~ source .zshrc
Final Thoughts:
I have created this tutorial some time ago, in portuguese.
Some plugins might have changed.
Hopefully you understand the method and are now able to configure your own plugins and themes.
Please read the instructions on the repositories before installing any plugins.
If you break your shell, just copy your .zshrc_backup and rename it to .zshrc.
Top comments (7)
Nice post! You may want to try out:
z-shell.pages.dev
great post! I like keeping things minimal and this really helped me out.
BTW there's another config for the .zsh_history file I found useful which automatically appends after every command rather than upon exiting the terminal
setopt INC_APPEND_HISTORY
Thanks for sharing!
I had a problem trying to customize the prompt character. The solution was to move
source $ZSH/themes/spaceship-prompt/spaceship.zsh-theme
to afterSPACESHIP_PROMPT_ORDER
.In my .zshrc file i don't have the PATH declared. What do i have to do?
Thanks
hello
Warning! The 'vi_mode' section was not found. Removing it from the prompt.
which package do i need to install to enable vi mode?
Set this option in your .zshrc
setopt vi
, or set your EDITOR to vim and you have it for free.