iTerm2 and Oh-My-Zsh Setup

This post is about set up efficient, beautiful theme emulator with oh-my-zsh.

Reference from: https://gist.github.com/kevin-smets/8568070

Install iTerm2

Install iTerm2 on Mac
https://www.iterm2.com/

Configure iTerm2

Solarized Dark is bad for some syntax highlighting, to import other themes, download from there, zip file, you can uncompress and put the downloaded folder to the user home directory, for example /Users/chengdol: https://iterm2colorschemes.com/

The theme I use is Chalk, import Chalk.itermcolors file(s) in the scheme(s) folder:

Additionally,go and set iTerm2:

1
2
3
4
5
Preference ->
Advanced ->
mouse ->
Scroll wheel sends arrow keys when in alternate screen mode ->
yes

This fix the mess-up issue when you scroll cursor inside Vim.

iTerm2 Tips

  1. Hotkeys, the floating terminal window setup:

Go to Preferences -> Keys -> Hotkey and create a Dedicated Hotkey Window. My customized hotkey is ctrl + shift + t. Set the hotkey window profiles text font the same as the default iTerm2 window, here I use MesloLGS NF.

  1. Locating the cursor in iTerm2 terminal: command + /.

  2. Send commands to mutliple panes in the same tab shift + command + i, disable use the same command.

  3. Go to split pane by direction: command + shift + arrow key.

  4. zsh cat command appends ‘%’ in line end if no newline at end.

Configure Oh My Zsh

Install ohmyz on Mac. Mac zsh is pre-installed, you can check by:

1
zsh --version

If not, install zsh first. Then install ohmyzsh:

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

Then install Powerlevel10k theme, this theme is what exactly I need:

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

By default it uses robbyrussell theme, you can see it from ~/.zshrc file, the theme files are located in ~/.oh-my-zsh/themes folder.

1
2
3
4
5
6
7
8
9
10
11
12
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git kubectl docker docker-compose gcloud)

Next when you start a new terminal session, the Powerlevel10 configure wizard will be launched to set your prompt pattern, it will automatically check and install the font for you. When select encoding, choose Unicode, otherwise no icon will show.

If you want to reset the configuration, simply run:

1
p10k configure

Powerlevel10 project web page: https://github.com/romkatv/powerlevel10k#extremely-customizable

Then set zsh as the default shell` on Mac: https://askubuntu.com/questions/131823/how-to-make-zsh-the-default-shell

1
2
3
4
5
6
7
## verify default shell is zsh or not
echo $SHELL

## If not zsh, set it
chsh -s $(which zsh)
## show current running shell
echo $0

After changing the theme, relaunch iTerm2.

~./zshrc works the same as ~/.bashrc for bash, append other alias here, append following snippet in ~/.zshrc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# ### some alias for convenience
alias cdd='cd ~/Desktop'
alias cdmb='cd ~/Desktop/chengdol.blog/'

## docker
alias di='docker images'
alias dp='docker ps'
alias drp='docker rm -f'
alias dri='docker rmi -f'
alias dl='docker logs -f'

function dexec()
{
docker exec -it $1 sh
}

## python virtual env
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
export WORKON_HOME="/Users/chengdol/virtualenvs"
export PROJECT_HOME="/Users/chengdol/virtualprojects"
alias svenv="source /Users/chengdol/virtualenvs/py3.10/bin/activate"

export OC_EDITOR=vim
export KUBE_EDITOR=vim

bindkey "^[^[[C" forward-word
bindkey "^[^[[D" backward-word
bindkey "^U" backward-kill-line

To list all shortcut in Zsh, run

1
bindkey

Reference:

Use cat command to see what exactly the key will present is a good idea.

Visual Studio Code Terminal

To make the VSC build-in terminal good with ohmyz theme, needs to add below setting to User VSC setting.json file(open by shift + command + P):

1
2
3
{
"terminal.integrated.fontFamily": "MesloLGS NF",
}

Then restart the VSC, the theme should be good.

Bash with Starship

Still using iTerm2, if you want to stick to Bash shell, try this:

Starship: cross shell prompt. https://starship.rs/

Install by running:

1
curl -fsSL https://starship.rs/install.sh | bash

After install, append this line in ~/.bashrc

1
eval "$(starship init bash)"

My config file:

1
mkdir -p ~/.config && touch ~/.config/starship.toml

My current ~/.config/starship.toml file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Disable the newline at the start of the prompt
add_newline = true

[line_break]
disabled = false

[character]
symbol = "➜"
error_symbol = "✗"
use_symbol_for_status = true

[battery]
full_symbol = "🔋"
charging_symbol = "⚡️"
discharging_symbol = "💀"

[time]
disabled = false
format = "🕙[ %T ]"
utc_time_offset = "-5"
time_range = "10:00:00-14:00:00"

[directory]
truncation_length = 8

## show virtual environments
[python]
disabled = false

[docker_context]
disabled = false
symbol = "🐋 "
only_with_files = true

[kubernetes]
symbol = "⛵ "
style = "dimmed green"
disabled = false

[terraform]
symbol = "🏎💨 "
disabled = false

[package]
disabled = true

[ruby]
disabled = true

[rust]
disabled = true

[nodejs]
disabled = true

[java]
disabled = true

[golang]
disabled = false

[aws]
disabled = true

## add more
0%