DEV Community

Discussion on: A Guide to Customizing the Zsh Shell Prompt

Collapse
 
synchromesh profile image
John Pallister

Thanks David, one question: what actually is the prompt format string you came up with for your own use? Cheers!

Collapse
 
voracious profile image
David R. Myers

Hey, thanks for reading through this article! I have adapted it since writing this article, but here is my current prompt string configuration (including the necessary bits for git status indicators).

parse_git_dirty() {
  git_status="$(git status 2> /dev/null)"
  [[ "$git_status" =~ "Changes to be committed:" ]] && echo -n "%F{green}·%f"
  [[ "$git_status" =~ "Changes not staged for commit:" ]] && echo -n "%F{yellow}·%f"
  [[ "$git_status" =~ "Untracked files:" ]] && echo -n "%F{red}·%f"
}

setopt prompt_subst

NEWLINE=$'\n'

autoload -Uz vcs_info # enable vcs_info
precmd () { vcs_info } # always load before displaying the prompt
zstyle ':vcs_info:git*' formats ' ↣ (%F{254}%b%F{245})' # format $vcs_info_msg_0_

PS1='%F{254}%n%F{245} ↣ %F{153}%(5~|%-1~/⋯/%3~|%4~)%F{245}${vcs_info_msg_0_} $(parse_git_dirty)$NEWLINE%F{254}$%f '
Enter fullscreen mode Exit fullscreen mode

This is what it looks like.

Enjoy!