tips

Setting up Z shell (zsh) on a new mac

Since the newer versions of OSX ship with a very old version of bash and Apple strongly recommends switching to zsh, I gave it a go.

Setting up Z shell (zsh) on a new mac

Since the newer versions of OSX ship with a very old version of bash and Apple strongly recommends switching to zsh, I gave it a go. At first it was a little disorienting, but after setting up a few plugins I can now call zsh my favourite shell.

To change your shell to zsh from bash, do the following:

chsh -s /bin/zsh

Next, I recommend installing the zinit plugin manager with the following two commands:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)"

zinit self-update

The prompt wasn’t as cool as I would have liked, but there are many options out there to customize it. I chose pure-prompt as I really liked the colorfulness and simplicity of it.

pure-prompt

To install pure-promt, you’ll need NodeJS before running the following command:

npm install --global pure-prompt

Lastly, you’ll need some configuration in your ~/.zshrc file:

# ~/.zshrc

zinit ice compile'(pure|async).zsh' pick'async.zsh' src'pure.zsh'
zinit light sindresorhus/pure

zinit wait lucid for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
    zdharma/fast-syntax-highlighting \
blockf \
    zsh-users/zsh-completions \
atload"!_zsh_autosuggest_start" \
    zsh-users/zsh-autosuggestions

# Configure keeping history of commands

HISTSIZE=200
HISTFILE=~/.zsh_history
SAVEHIST=200
setopt appendhistory
setopt sharehistory
setopt incappendhistory

# Key bindings: (find the codes with `cat` and pressing key)

# alt-right-arrow - move one word forward
bindkey "^[^[[C" forward-word
# alt-left-arrow - move one word back
bindkey "^[^[[D" backward-word 
# delete-key - delete the character under the cursor
bindkey "^[[3~" delete-char
# home-key - move to the beginning of the line
bindkey "^[[H" beginning-of-line
# end-key - move to the end of the line
bindkey "^[[F" end-of-line