Created
January 15, 2024 09:05
-
-
Save kidpixo/b87fca9b56801652b4ca725422d5c250 to your computer and use it in GitHub Desktop.
git function for bash prompt, adding current branch and untracked/new files
This file contains 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_prompt () | |
{ | |
# see [Setting color on git status in bash prompt - Stack Overflow](http://stackoverflow.com/questions/24837340/setting-color-on-git-status-in-bash-prompt) | |
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 0 ] | |
then | |
local GIT_PROMPT="${RESET}(${DIM}g${RESET}|" | |
git_branch () { git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; } | |
# assemblate status statistic,substitute ? with U | |
git_status () { git status --porcelain 2>/dev/null | cut -c 1-2 | sort | uniq -c | sed 's/ *//;s/ */:/;s/\?/U/g' | paste -sd "|" -; } | |
if [ "$(git_status)" != "" ] | |
then | |
local GIT_BRANCH="$RED$(git_branch)$RESET" | |
local GIT_PROMPT=$GIT_PROMPT$GIT_BRANCH | |
local GIT_STATUS="|"$RED$(git_status)$RESET | |
local GIT_PROMPT=$GIT_PROMPT$GIT_STATUS | |
else | |
local GIT_BRANCH="$GREEN$(git_branch)$RESET" | |
local GIT_PROMPT=$GIT_PROMPT$GIT_BRANCH | |
fi | |
local GIT_PROMPT=$GIT_PROMPT")" | |
else | |
local GIT_PROMPT="" | |
fi | |
echo -n $GIT_PROMPT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment