Skip to content

Instantly share code, notes, and snippets.

@minhanhhere
Last active May 2, 2024 02:09
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save minhanhhere/4a124522b2931dd47fa0aed56ad9843e to your computer and use it in GitHub Desktop.
Save minhanhhere/4a124522b2931dd47fa0aed56ad9843e to your computer and use it in GitHub Desktop.
Customise Your Terminal Using Zsh & powerlevel10k

What we will setup

1. ZSH

ZSH, also called the Z shell, is an extended version of the Bourne Shell (sh), with plenty of new features, and support for plugins and themes.

2. oh-my-zsh

This is a framework for zsh

3. Powerlevel 10k

Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience.

4. Zsh-syntax-highlighting

This package provides syntax highlighting for the shell zsh. It enables highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.

5. Zsh-autosuggestions

As you type commands, you will see a completion offered after the cursor in a muted gray color. If you press the → key (forward-char widget) or End (end-of-line widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.

6. Git-completion

1. Install ZSH

# ZSH is installed by default in MacOs.
# To make it the default shell run this
chsh -s $(which zsh)

2. Install oh-my-zsh

Follow the instruction here https://ohmyz.sh/ Or use this snippet:

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

3. Install and Cofigure powerlevel10k

i. Fonts

Install the fonts:

https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

cd ~/Library/Fonts && {
    curl 'https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Regular.ttf' --output 'MesloLGS NF Regular.ttf'
    curl 'https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Bold.ttf' --output 'MesloLGS NF Bold.ttf'
    curl 'https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Italic.ttf' --output 'MesloLGS NF Italic.ttf'
    curl 'https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Bold%20Italic.ttf' --output 'MesloLGS NF Bold Italic.ttf'
    cd -; }

Open Terminal → Preferences → Profiles → Text, click Change beside Font and select MesloLGS NF family

ii. Installation

mkdir -p ~/.zsh
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.zsh/powerlevel10k
echo 'source ~/.zsh/powerlevel10k/powerlevel10k.zsh-theme'>>~/.zshrc

iii. Configure

Exit the Terminal. Open it again and follow the wizard to configure the theme. Refer to the new zshrc file for the final configuration.

iv. Custom color

We can change the .p10k.zsh at POWERLEVEL9K_DIR_BACKGROUND:

typeset -g POWERLEVEL9K_DIR_BACKGROUND=5

4. Install Zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
echo 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh'>>~/.zshrc

5. Install Zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
echo 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh'>>~/.zshrc

6. Install git-completion

Download this file. Move it to ~/.zsh/. https://github.com/minhanhhere/developer-tools/raw/main/powerlevel10k/git-completion.bash

mkdir -p ~/.zsh && cd ~/.zsh && {
    curl -O 'https://raw.githubusercontent.com/minhanhhere/developer-tools/main/powerlevel10k/git-completion.bash'
    cd -; }

echo "

# Load Git completion
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh \$fpath)
autoload -Uz compinit && compinit
">>~/.zshrc

7. Recommended zshrc

Recommended: Download this and replace with your .zshrc

https://github.com/minhanhhere/developer-tools/raw/main/powerlevel10k/.zshrc

# add git integration vcs_info
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
zstyle ':vcs_info:git:*' formats '%F{93}%r (%b)%f'
zstyle ':vcs_info:*' enable git
# λ
#PROMPT=$'%B%F{39}%/%f%b $vcs_info_msg_0_%F{166}\nλ %f'
PROMPT=$'%B%F{39}%2/%f%b $vcs_info_msg_0_%F{166}\nλ %f'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias edit='open -a TextEdit'
export CLICOLOR=1
export PATH="$PATH:/Users/minhanh/Development/flutter/bin"
export GOOGLE_APPLICATION_CREDENTIALS="/Users/minhanh/nasa-ad540-firebase-adminsdk-ijqav-f24d442b0f.json"
@minhanhhere
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment