My minimalist prompt setup on zsh + oh-my-zsh

Jamie Wen
2 min readAug 9, 2020

--

Prompt just enough info in your terminal

If you haven’t set up your shell environment on Mac, please check out πŸ‘‰ My minimalist shell setup β€” Bash in Terminal and Zsh in iTerm2

Here’s what my minimalist prompt setup looks like

My minimalist prompt setup

The configuration behind the scenes

PROMPT='%(?.πŸ˜€.😱)%(!.%{$fg[red]%}.%{$fg[green]%})%2~%{$fg_bold[blue]%}$(git_prompt_info) %F{205}>%F{196}>%F{220}> %{$reset_color%} 'ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" βœ—"
ZSH_THEME_GIT_PROMPT_CLEAN=" βœ”"

How should I use your config?

  1. Install iTerm2, zsh, on-my-zsh (I am using Mac)

2. Create your own theme file in ~/.oh-my-zsh/themes , e.g. blah.zsh-theme

3. Copy the above config to the theme file you just created

4. Open ~/.zshrc and change the ZSH_THEME="blah"

5. Restart your Terminal

What it does?

Highlight the return status

emoji the return status

%(?.πŸ˜€.😱)

%? The return status of the last command was executed just before the prompt.

Highlight privileges

%(!.%{$fg[red]%}.%{$fg[green]%})

%(x.true-text.false-text) True if the shell is running with privileges.

Shorten the path

use ~ represents $HOME
show current directory and its parent directory only

%2~ show current directory and its parent, use ~ represents $HOME

%2 The value of the first element of the psvar array parameter.

%~ As %d and %/, if the current working directory starts with $HOME, that part is replaced by a β€˜~’. Furthermore, if it has a named directory as its prefix, that part is replaced by a β€˜~’ followed by the name of the directory, but only if the result is shorter than the full path;

Show git info

$(git_prompt_info)ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" βœ—"
ZSH_THEME_GIT_PROMPT_CLEAN=" βœ”"

Prompt input

%F{205}>%F{196}>%F{220}> show three > in a different color

%F Start (stop) using a different foreground colour, if supported by the terminal.

--

--

Jamie Wen
Jamie Wen

Written by Jamie Wen

Software Engineer | Technical Lead | Engineering Manager https://justlearning.club

No responses yet