Skip to content

Instantly share code, notes, and snippets.

@ColtHands
Last active May 29, 2025 06:01
Show Gist options
  • Save ColtHands/2a2a0ce08676667a8dd5252353bac810 to your computer and use it in GitHub Desktop.
Save ColtHands/2a2a0ce08676667a8dd5252353bac810 to your computer and use it in GitHub Desktop.
My zshell config
get_git_branch() {
git rev-parse --abbrev-ref HEAD 2>/dev/null
}
get_git_repo() {
basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null
}
has_unstaged_changes() {
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
echo " +"
fi
}
has_commits_to_push() {
local branch=$(get_git_branch)
if [[ -n $(git rev-list origin/"${branch}"..HEAD 2>/dev/null) ]]; then
echo "↑"
fi
}
has_commits_to_pull() {
local branch=$(get_git_branch)
local count=$(git rev-list HEAD..origin/"${branch}" --count 2>/dev/null)
if [[ ${count} -gt 0 ]]; then
echo "↓"
fi
}
display_arrows() {
local has_push=$(has_commits_to_push)
local has_pull=$(has_commits_to_pull)
if [[ -n ${has_push} || -n ${has_pull} ]]; then
echo " ${has_push}${has_pull}" # Concatenate arrows without spaces
elif [[ -n ${has_push} ]]; then
echo " ${has_push}"
elif [[ -n ${has_pull} ]]; then
echo " ${has_pull}"
else
echo ""
fi
}
update_prompt() {
local branch=$(get_git_branch)
local has_unstaged=$(has_unstaged_changes)
local has_push=$(has_commits_to_push)
local has_pull=$(has_commits_to_pull)
local arrows=$(display_arrows)
PROMPT="%F{cyan}[%D{%H:%M:%S}]%f %F{blue}%~%f %F{green}${branch}%f%F{red}${has_unstaged}%f%F{yellow}${arrows}%f λ "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment