Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active March 18, 2021 23:15
Show Gist options
  • Save jayers99/21fc26038c9d40c238dceeb183301299 to your computer and use it in GitHub Desktop.
Save jayers99/21fc26038c9d40c238dceeb183301299 to your computer and use it in GitHub Desktop.
zsh prompt with out oh-my-zsh
# setup for prompt
autoload colors; colors;
export LSCOLORS=ExFxBxDxCxegedabagacad
# export LSCOLORS="Gxfxcxdxbxegedabagacad"
setopt prompt_subst
# prompt
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}%{$fg[blue]%}(%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[blue]%})%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
NEWLINE=$'\n'
# show git branch/tag, or name-rev if on detached head
parse_git_branch() {
(command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null
}
# show red star if there are uncommitted changes
parse_git_dirty() {
if command git diff-index --quiet HEAD 2> /dev/null; then
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
else
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
fi
}
# if in a git repo, show dirty indicator + git branch
git_custom_status() {
local git_where="$(parse_git_branch)"
[ -n "$git_where" ] && echo "$ZSH_THEME_GIT_PROMPT_PREFIX${git_where#(refs/heads/|tags/)}$ZSH_THEME_GIT_PROMPT_SUFFIX$(parse_git_dirty)"
}
# all that stuff for this custom prompt
PROMPT='%{$fg[yellow]%}%n@%m%f:%{$fg[cyan]%}%~% $(git_custom_status) ${NEWLINE}%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment