mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-05 01:46:46 +01:00
30 lines
956 B
Bash
30 lines
956 B
Bash
# get the name of the branch we are on
|
|
function git_prompt_info() {
|
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
|
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
|
}
|
|
|
|
parse_git_dirty () {
|
|
gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
|
|
|
|
if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
|
|
echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
|
fi
|
|
|
|
if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then
|
|
echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
|
fi
|
|
|
|
if [[ $(echo ${gitstat} | grep -v '^$' | wc -l | tr -d ' ') == 0 ]]; then
|
|
echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Will return the current branch name
|
|
# Usage example: git pull origin $(current_branch)
|
|
#
|
|
function current_branch() {
|
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
|
echo ${ref#refs/heads/}
|
|
}
|