Created
September 21, 2025 14:11
-
-
Save jgentes/a0f025e2bf69946d01d69b4fa77b04cc to your computer and use it in GitHub Desktop.
latest ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Git status function for PS1 | |
| git_status() { | |
| if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
| return | |
| fi | |
| local branch=$(git branch 2>/dev/null | grep "^*" | colrm 1 2) | |
| local status="" | |
| # Check if we're ahead or behind | |
| local ahead=$(git rev-list --count @{upstream}..HEAD 2>/dev/null || echo "0") | |
| local behind=$(git rev-list --count HEAD..@{upstream} 2>/dev/null || echo "0") | |
| if [ "$ahead" -gt 0 ] && [ "$behind" -gt 0 ]; then | |
| status=" $(tput setaf 3)↕$ahead/$behind$(tput sgr0)" | |
| elif [ "$ahead" -gt 0 ]; then | |
| status=" $(tput setaf 2)↑$ahead$(tput sgr0)" | |
| elif [ "$behind" -gt 0 ]; then | |
| status=" $(tput setaf 1)↓$behind$(tput sgr0)" | |
| fi | |
| echo "$branch$status" | |
| } | |
| # Define colors using tput for better compatibility | |
| CYAN=$(tput setaf 6) | |
| GREEN=$(tput setaf 2) | |
| RESET=$(tput sgr0) | |
| export PS1='\[$(tput setaf 6)\] \w\[$(tput setaf 2)\] - $(git_status)\[$(tput sgr0)\] \$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment