CrypticCrazeForCS

Coz ‘blogging’ sounds way cooler than ‘making-notes’

Customising oh-my-zsh in MacOS

--

Current View

This is how my terminal looks as of 25th October, 2020

current iterm configuration

I use iTerm whose features are listed in the link. You can download iTerm from the given link, and use it as the default terminal.

Installing zsh

zsh is the default shell I use. Install zsh using brew. Steps involved are:

  • If brew is not installed, install it using:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Now that brew is installed, install zsh using
brew install zsh

Setting up zsh as default shell

Check thatzsh has been installed (check it using zsh --version, if this outputs the version of zsh, that means that installation is complete).

Now, change the default shell to zsh using the following steps:

  • Check where zsh actually is. which zsh should output something like /usr/local/bin/zsh or /bin/zsh.
  • chsh is the command to change the shell. However:

chsh will accept the full pathname of any executable file on the system. However, it will issue a warning if the shell is not listed in the /etc/shells file.

To do away with the above warning, add zsh to /etc/shells using:

sudo sh -c "echo $(which zsh) >> /etc/shells"
  • Change the default shell to zsh using
sudo chsh -s $(which zsh)

Now, your /etc/shells should look something like this:

content of /etc/shells

Restart your terminal (some versions of Yosemite, you may need to restart the system as well) and zsh should be set as your default shell. You can check it using echo $SHELL.

Oh-My-Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

Installating oh-my-zsh

The following command should install oh-my-zsh.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Configuring oh-my-zsh

Open the ~/.zshrc file, and you’ll see a lot of options there. You can go ahead and play with some of those options. To reflect the changes on the session, use the command source ~/.zshrc.

We’ll now add the plugins and themes required.

Plugins and themes

Here you’ll find most of the plugins for oh-my-zsh.

I found the following plugins and themes to be quite useful:

Installing plugins

zsh-autosuggestions

Run the following command to clone the zsh-autosuggestions library (the following is one line of code):

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Next add zsh-autosuggestions as plugins in ~/.zshrc file

plugins=(zsh-autosuggestions)

zsh-syntax-highlighting

Clone the zsh-syntax-highlighting library

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Activate the plugin in ~/.zshrc file

plugins=(zsh-syntax-highlighting) 

Now run source ~/.zshrc to check how the changes appear.

Powerlevel10k

This is the theme which we are going to use.

Installation

To install, simply clone:

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

and add the theme in ~/.zshrc

ZSH_THEME="powerlevel10k/powerlevel10k"

Fonts

Download these files:

  1. MesloLGS NF Regular.ttf
  2. MesloLGS NF Bold.ttf
  3. MesloLGS NF Italic.ttf
  4. MesloLGS NF Bold Italic.ttf

Now double click on each file to install them. Once installed, Open iTerm2 → Preferences → Profiles → Text and set Font to MesloLGS NF.

Configuration

Simply run p10k configure and select the options you like.

Once this is done, you should see a really good terminal.

Manually Configuring the colors and prompts

Open the ~/.p10k.zsh file, and you’ll find options to edit the prompt elements:

typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status                  # exit code of the last commandcommand_execution_time  # duration of the last command....
....
....
battery # internal battery# wifi # wifi speed# example # example user-defined segment (see prompt_example function below))

Uncomment the ones you want to keep.

The color options are present below that:

# Current directory background color.typeset -g POWERLEVEL9K_DIR_BACKGROUND=24# Default current directory foreground color.typeset -g POWERLEVEL9K_DIR_FOREGROUND=254# If directory is too long, shorten some of its segments to the shortest possible unique# prefix. The shortened directory can be tab-completed to the original.typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique# Replace removed segment suffixes with this symbol.typeset -g POWERLEVEL9K_SHORTEN_DELIMITER=# Color of the shortened directory segments.typeset -g POWERLEVEL9K_DIR_SHORTENED_FOREGROUND=250# Color of the anchor directory segments. Anchor segments are never shortened. The first# segment is always an anchor.typeset -g POWERLEVEL9K_DIR_ANCHOR_FOREGROUND=255# Display anchor directory segments in bold.

Since the colors are numbers, you’ll need a mapping of numbers to colors to display the color you want.

To display all the colors your terminal supports along with the number, type the following in iTerm:

for i in {0..255}; do print -Pn "%K{$i}  %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}; done

That should print something like:

numbers against the colors they represent

Choose the background and foreground colors you like.

Congratulations! Your terminal has all been setup.

--

--

CrypticCrazeForCS
CrypticCrazeForCS

Published in CrypticCrazeForCS

Coz ‘blogging’ sounds way cooler than ‘making-notes’

Shadow
Shadow

Written by Shadow

Discrete love for maths, cryptic craze for Computer Science. Often switch to songs and fiction for solace.

No responses yet