I’m doing some development on the mac platform and often using terminal for running commands and especially checking the code I’m writing into version control with git.

1. Search history
At the command line you can already use the up (“^[[A”) and down (“^[[B”) keys to go through your previously executed commands, however it’s annoying if you want to quickly repeat a command you used a few steps ago but need to keep scrolling up through your history. You can change the behaviour using ‘history-beginning-search-backward’ (and forward), and you can type, for example ‘python’ and it will search through all previous commands starting with this ‘python -m unittest’, ‘python run.py’, python -m venv env’ or whatever, without showing other commands you used in between. A very simple change but really useful. Just add the following to ‘~/.zshrc’; then ‘source ~/.zshrc’ to reload the zsh profile:

# start search history
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward
# end search history

2. Current git branch in prompt
I find it really helpful to know the current git branch in the folder I’m working in. Although you can see this in VS code in the status bar, it reflects the VS code open folder, rather than where your prompt is currently active. Add the following to ‘~/.zshrc’:

# start git branch view
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT=' %~ %F{blue}${vcs_info_msg_0_}%F{white} > '
# end git branch view

3. Full path at current prompt
On Ubuntu the terminal displays the full path, which is very handy to see where you are. The default on mac is to show only the current folder (add ‘%1d’ in the PROMPT), but I prefer to see the whole path relative to home (‘%~’).

I’ve also removed ‘%n@%m’ which would show the username @ machine name, as I don’t care about these, and swapped ‘$’ prompt for the class DOS ‘>’. So now I have a nice clean prompt which shows me just the info I need!

Oh My Zsh is recommended as a full on theme and framework for terminal, but these few items serve all my needs for now.