Skip to content

Instantly share code, notes, and snippets.

@mcwalrus
Last active October 25, 2024 21:55
Show Gist options
  • Save mcwalrus/95221522fe62f91960c849688090ccfb to your computer and use it in GitHub Desktop.
Save mcwalrus/95221522fe62f91960c849688090ccfb to your computer and use it in GitHub Desktop.
Minimal zsh theme
# write to ~/.oh-my-zsh/themes/minimal-3.zsh-theme
# then set ~/.zshrc ZSH_THEME='minimal-3'
# Define colors
autoload -U colors && colors
SUCCESS_COLOR=$fg[green]
ERROR_COLOR=$fg[red]
TEXT_COLOR=$fg[black] # Set printout text color to black
RESET_COLOR=$reset_color
# Prompt components
build_prompt() {
# Status of last command
if [[ $? -eq 0 ]]; then
STATUS="${SUCCESS_COLOR}✔${RESET_COLOR}"
else
STATUS="${ERROR_COLOR}✘${RESET_COLOR}"
fi
# Show only the current directory name in black
local dir_name="${TEXT_COLOR}%2~${RESET_COLOR}"
# Git branch
local git_branch=""
if git rev-parse --is-inside-work-tree &>/dev/null; then
git_branch="${TEXT_COLOR}$(git rev-parse --abbrev-ref HEAD)${RESET_COLOR}"
# Check for modifications or untracked files
if [[ -n $(git status --porcelain) ]]; then
git_branch="${git_branch}*"
fi
fi
# Display prompt with components
PROMPT="${STATUS} ${dir_name} ${git_branch} > "
}
# Set prompt function
precmd() { build_prompt }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment