Skip to content

Instantly share code, notes, and snippets.

@aamnah
Last active October 17, 2024 16:18
Show Gist options
  • Save aamnah/b50b081a752f6e193f9202c2c445b740 to your computer and use it in GitHub Desktop.
Save aamnah/b50b081a752f6e193f9202c2c445b740 to your computer and use it in GitHub Desktop.
Cheats and helpers for creating a custom oh-my-zsh theme and git prompt

Zsh custom git prompt cheatsheet

Everything you need for customizing your git prompt in oh-my-zsh

  • print and echo commands for all functions in the git plugin. Printing and echoing because then i can check what values are outputted. Massively helpful when creating a theme.
  • a list of all the variables that you can use to customize $(git_prompt_info), thanks to vergenzt
grep -o "ZSH_THEME_GIT_[A-Z_]\+" lib/git.zsh| sort | uniq
$(git_prompt_info) # Outputs current branch info in prompt format
$(parse_git_dirty) # Checks if working tree is dirty
$(git_remote_status) # Gets the difference between the local and remote branches
$(git_current_branch) # Outputs the name of the current branch
$(git_commits_ahead) # Gets the number of commits ahead from remote
$(git_commits_behind) # Gets the number of commits behind remote
$(git_prompt_ahead) # Outputs if current branch is ahead of remote
$(git_prompt_behind) # Outputs if current branch is behind remote
$(git_prompt_remote) # Outputs if current branch exists on remote or not
$(git_prompt_short_sha) # Formats prompt string for current git commit short SHA
$(git_prompt_long_sha) # Formats prompt string for current git commit long SHA
$(git_prompt_status) # Get the status of the working tree
$(git_current_user_name) # Outputs the name of the current user
$(git_current_user_email) # Outputs the email of the current user
$(git_repo_name) # Output the name of the root directory of the git repository
# Get plain text output
echo -e "git_prompt_info: $(git_prompt_info)"
echo -e "parse_git_dirty: $(parse_git_dirty)"
echo -e "git_remote_status: $(git_remote_status)"
echo -e "git_current_branch: $(git_current_branch)"
echo -e "git_commits_ahead: $(git_commits_ahead)"
echo -e "git_commits_behind: $(git_commits_behind)"
echo -e "git_prompt_ahead: $(git_prompt_ahead)"
echo -e "git_prompt_behind: $(git_prompt_behind)"
echo -e "git_prompt_remote: $(git_prompt_remote)"
echo -e "git_prompt_short_sha: $(git_prompt_short_sha)"
echo -e "git_prompt_long_sha: $(git_prompt_long_sha)"
echo -e "git_prompt_status: $(git_prompt_status)"
echo -e "git_current_user_name: $(git_current_user_name)"
echo -e "git_current_user_email: $(git_current_user_email)"
echo -e "git_repo_name: $(git_repo_name)"
# Get colored output
print -P "git_prompt_info: $(git_prompt_info)"
print -P "parse_git_dirty: $(parse_git_dirty)"
print -P "git_remote_status: $(git_remote_status)"
print -P "git_current_branch: $(git_current_branch)"
print -P "git_commits_ahead: $(git_commits_ahead)"
print -P "git_commits_behind: $(git_commits_behind)"
print -P "git_prompt_ahead: $(git_prompt_ahead)"
print -P "git_prompt_behind: $(git_prompt_behind)"
print -P "git_prompt_remote: $(git_prompt_remote)"
print -P "git_prompt_short_sha: $(git_prompt_short_sha)"
print -P "git_prompt_long_sha: $(git_prompt_long_sha)"
print -P "git_prompt_status: $(git_prompt_status)"
print -P "git_current_user_name: $(git_current_user_name)"
print -P "git_current_user_email: $(git_current_user_email)"
print -P "git_repo_name: $(git_repo_name)"
ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX=""
ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX=""
ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX=""
ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX=""
ZSH_THEME_GIT_PROMPT_ADDED=""
ZSH_THEME_GIT_PROMPT_AHEAD=""
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=""
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR=""
ZSH_THEME_GIT_PROMPT_BEHIND=""
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE=""
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DELETED=""
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_DIVERGED=""
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE=""
ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE=""
ZSH_THEME_GIT_PROMPT_MODIFIED=""
ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS=""
ZSH_THEME_GIT_PROMPT_REMOTE_MISSING=""
ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED=""
ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX=""
ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX=""
ZSH_THEME_GIT_PROMPT_RENAMED=""
ZSH_THEME_GIT_PROMPT_SHA_AFTER=""
ZSH_THEME_GIT_PROMPT_SHA_BEFORE=""
ZSH_THEME_GIT_PROMPT_STASHED=""
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_UNMERGED=""
ZSH_THEME_GIT_PROMPT_UNTRACKED=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment