User Tools

Site Tools


linux:ubuntu_zsh_without_omz

Ubuntu Zsh Without Oh My Zsh

Everybody loves Zsh. And most, if not every tutorial teaches to use Oh My Zsh (OMZ) to manage plugins and themes. But the truth is, you can do all of that without Oh My Zsh. Also OMZ makes the terminal really slow. You will probably only utilize about 5 to 10 percent of all the stuff that's shipping with OMZ so why not utilize Zsh with only the stuff you need and keep your shell responsive and fast ?

It's pretty straight forward really just add the following line to your .zshrc file.

source path/to/your/plugin

That's actually all there is to it. This guide will show you how to install zsh as our new shell as well as the following:

  • Theme - agnoster link
  • Plugin - colored-man-pages link
  • Plugin - zsh-autosuggestions link
  • Plugin - fast-syntax-highlighting link
  • Plugin - zsh-completions link

Unistall Oh My ZSH

Open a terminal and type the following.

cd ~
cp .zshrc .zshrc.backup
uninstall_oh_my_zsh

In order for these changes to take effect you will have to log out and in again on your system. After login out and back in again you may be prompted with a zsh initial configuration screen when opening the terminal. This can be ignored. Just select (q) to quit this screen.

Installing Zsh

If you need to install zsh because (OMZ) reverted you back to a bash shell or if you did not infact had (OMZ) installed it can be done like this.

sudo apt install zsh
chsh -s /usr/bin/zsh

In order for these changes to take effect you will have to log out and in again on your system. After login out and back in again you may be prompted with a zsh initial configuration screen when opening the terminal. This can be ignored. Just select (q) to quit this screen.

Getting Things Set Up

Now in this guide we are going to keep everything zsh related under the directory .zsh

cd ~
mkdir -p .zsh/plugins .zsh/themes
touch .zsh/.zshrc
touch .zsh/.zsh_history
touch .zsh/.zsh_alias

History Optional:
moving your OMZ history file to the new setup.

mv .zsh_history .zsh/

Configuration Minimum

Add the following to your .zsh/.zshrc configuration file.

# ZSH CONFIGUATION
#
# HOME DIR
export ZSH=$HOME/.zsh

# HISTORY FILE
export HISTFILE=$ZSH/.zsh_history

# HISTORY NUMBER OF COMMANDS REMEMBERED
export HISTSIZE=10000

# HISTORY NUMBER OF COMMANDS SAVED TO FILE
export SAVEHIST=10000

# HISTORY DON'T SAVE DUPLICATES
setopt HIST_IGNORE_ALL_DUPS

# HISTORY DON'T SHOW DUPLICATES ON SEARCH
setopt HIST_FIND_NO_DUPS

# HISTORY APPEND INSTEAD OF REPLACE
setopt APPEND_HISTORY

# EDITOR OPTIONAL SET TO VI
setopt vi

# PROMPT
setopt prompt_subst

Custom Path Optional
I like to put a custom path in the configuration file you can. You can see you current path like this.

echo $PATH

We are going to add a quite simple path in this example. Don't use this one use your own this is just an example.

/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/snap/bin:/snap/bin

Add that to your .zsh/.zshrc configuration file at the top it should look a bit like this.

export PATH=$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/snap/bin:/snap/bin:$PATH

Swith To The New Configuration

So far nothing has changed zsh is still using the old config file. We are changing this now. Remove the old ~/.zshrc (keep the backup)

cd ~
rm .zshrc
ln -s -T .zsh/.zshrc .zshrc
source .zshrc

Note The .zshrc file may not exist when you try to delete it which is fine.

Theme

The Agnoster theme requires a specific font called Powerline to be installed in order to work you can install it like this.

sudo apt install fonts-powerline

Next lets grap the theme.

cd .zsh/themes
git clone https://github.com/agnoster/agnoster-zsh-theme.git

Tell zsh to use the Agnoster thene. Add the following to your .zsh/.zshrc configuration file.

# THEME
source $ZSH/themes/agnoster-zsh-theme/agnoster.zsh-theme

Your configuration file should now look something like this.

# ZSH CONFIGUATION

# HOME DIR
export ZSH=$HOME/.zsh

# HISTORY FILE
export HISTFILE=$ZSH/.zsh_history

# HISTORY NUMBER OF COMMANDS REMEMBERED
export HISTSIZE=10000

# HISTORY NUMBER OF COMMANDS SAVED TO FILE
export SAVEHIST=10000

# HISTORY DON'T SAVE DUPLICATES
setopt HIST_IGNORE_ALL_DUPS

# HISTORY DON'T SHOW DUPLICATES ON SEARCH
setopt HIST_FIND_NO_DUPS

# HISTORY APPEND INSTEAD OF REPLACE
setopt APPEND_HISTORY

# EDITOR OPTIONAL SET TO VI
setopt vi

# PROMPT
setopt prompt_subst

# THEME
source $ZSH/themes/agnoster-zsh-theme/agnoster.zsh-theme

Im not really fan of the colors so I set my terminal to use the Solarized theme. You can do this in the preference menu in your terminal.

Plugins

cd ~/.zsh/plugins

Now clone the following plugins

git clone https://github.com/zdharma-zmirror/fast-syntax-highlighting.git
git clone https://github.com/zsh-users/zsh-autosuggestions.git
git clone https://github.com/ael-code/zsh-colored-man-pages.git
git clone https://github.com/zsh-users/zsh-completions.git

Zsh Completions is loaded differently like this: fpath=($ZSH/plugins/zsh-completions/src $fpath)

Enabling the plugins
Add the following to your .zshrc configuration file.

# PLUGINS
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZSH/plugins/zsh-colored-man-pages/colored-man-pages.plugin.zsh

# PLUGIN Zsh Completions
fpath=($ZSH/plugins/zsh-completions/src $fpath)

Your zsh configuration file should no look something like this. Nice clean uncluttered and fast.

# ZSH CONFIGUATION

# HOME DIR
export ZSH=$HOME/.zsh

# HISTORY FILE
export HISTFILE=$ZSH/.zsh_history

# HISTORY NUMBER OF COMMANDS REMEMBERED
export HISTSIZE=10000

# HISTORY NUMBER OF COMMANDS SAVED TO FILE
export SAVEHIST=10000

# HISTORY DON'T SAVE DUPLICATES
setopt HIST_IGNORE_ALL_DUPS

# HISTORY DON'T SHOW DUPLICATES ON SEARCH
setopt HIST_FIND_NO_DUPS

# HISTORY APPEND INSTEAD OF REPLACE
setopt APPEND_HISTORY

# EDITOR OPTIONAL SET TO VI
setopt vi

# PROMPT
setopt prompt_subst

# THEME
source $ZSH/themes/agnoster-zsh-theme/agnoster.zsh-theme

# PLUGINS
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZSH/plugins/zsh-colored-man-pages/colored-man-pages.plugin.zsh

# PLUGIN Zsh Completions
fpath=($ZSH/plugins/zsh-completions/src $fpath)

Close and open your terminal again for the changes to take effect.

Note Regarding Zsh Completions. From the documentation from the developers site there is a note that says you may need to execute the following command in order to make this work. I did not have to do this though.

rm -f ~/.zcompdump; compinit

Alias

Normally aliases would go into your .zshrc file, but I find this pollutes the configuration file. Another solution is to use a seperate file for aliases. This can be achieved by putting these lines in your configuration file.

# Alias
if [ -f ~/.zshalias ]; then
    source ~/.zshalias
    print "404: ~/.zshalias not found."

Your configuration file should no look something like this.

# ZSH CONFIGUATION

# HOME DIR
export ZSH=$HOME/.zsh

# HISTORY FILE
export HISTFILE=$ZSH/.zsh_history

# HISTORY NUMBER OF COMMANDS REMEMBERED
export HISTSIZE=10000

# HISTORY NUMBER OF COMMANDS SAVED TO FILE
export SAVEHIST=10000

# HISTORY DON'T SAVE DUPLICATES
setopt HIST_IGNORE_ALL_DUPS

# HISTORY DON'T SHOW DUPLICATES ON SEARCH
setopt HIST_FIND_NO_DUPS

# HISTORY APPEND INSTEAD OF REPLACE
setopt APPEND_HISTORY

# EDITOR OPTIONAL SET TO VI
setopt vi

# PROMPT
setopt prompt_subst

# THEME
source $ZSH/themes/agnoster-zsh-theme/agnoster.zsh-theme

# PLUGINS
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZSH/plugins/zsh-colored-man-pages/colored-man-pages.plugin.zsh

# PLUGIN Zsh Completions
fpath=($ZSH/plugins/zsh-completions/src $fpath)

# Alias
if [ -f $ZSH/.zsh_alias ]; then
    source $ZSH/.zsh_alias
else
    print "404: $ZSH/.zsh_alias not found."
fi

And we are done. Close and open your shell in order for changes to take effect.

linux/ubuntu_zsh_without_omz.txt · Last modified: 24/03/2024 17:43 by Allan