MacOS zsh terminal themes and prompt customisation

A while back I stumbled across basic zsh prompt customisation to show the current git branch I’m working on. Some point later I also added oh-my-zsh but kept the default theme as it worked fine for my needs and was unobtrusive.

At some point recently I had a couple of terminal customisation videos come up in my recommended feed, and watching one out of curiousity I was amazed at just how far you can go, especially with displaying all sorts of info as badges in your prompt.

Just so I don’t forget how I got here, I installed powerlevel10k using brew:

brew install powerlevel10k
echo "source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme" >>~/.zshrc

and then used the interactive customisation menus which run if you restart zsh with:

exec zsh

MacOS curl error: “zsh: no matches found”

I’ve seen this error before with MacOS’s zsh and I can never remember what the issue is:

> curl https://localhost:8080/example?email=test
zsh: no matches found: https://localhost:8080/example?email=test

You can get this error with multiple different commands for the same reason. The ‘?’ in the param to curl is interpreted as a substitution wildcard character. To avoid the issue, either escape the ? as \? or just wrap the whole url in double quotes.

Simplest customization of MacOS zsh prompt with git branch name without escape codes

In my previous zsh configuration that I combined from multiple sources there’s an issue with backspace when moving back through a longer line. The cursor jumps up or down a line and behaves weirdly.

From some searches online, it appears I have an issue with the escape codes not starting and ending correctly. Rather than spending time debugging what’s going on, I simplified it to avoid using the escape codes using suggestions in this question:

function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}

setopt PROMPT_SUBST
export PROMPT='%n %~ %F{green}$(parse_git_branch)%F{reset_color} > '

This approaches uses the built in color codes, e.g. $F{green} instead of using the escape codes that need to be correctly terminated.