PS1 : show git branch when not in dotfiles.

This commit is contained in:
Dmitry Voronin 2023-12-04 13:32:44 +03:00
parent 8bd6946470
commit b7d4c77088
2 changed files with 36 additions and 3 deletions

View file

@ -87,6 +87,37 @@ _git_current_branch()
git branch --show-current 2> /dev/null git branch --show-current 2> /dev/null
} }
# Show origin's url.
_git_origin_url()
{
git remote get-url origin
}
# Get this dotfiles url.
_git_dotfiles_url()
{
echo 'https://git.voronind.com/voronind/linux.git'
}
# Check if current git repo is this dotfiles.
_git_is_dotfiles()
{
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
local dir="${PWD}"
while [[ "${dir}" != "" ]]; do
if [[ -d "${dir}/.git" ]]; then
if [[ "${dir}" = "${HOME}" ]]; then
return 0
else
return 1
fi
fi
dir="${dir%/*}"
done
}
# autocomplete. # autocomplete.
_completion_loader git &> /dev/null _completion_loader git &> /dev/null
__git_complete gps _git_push &> /dev/null __git_complete gps _git_push &> /dev/null

View file

@ -44,9 +44,11 @@ __prompt_command()
# PS1+="\${PWD}" # PS1+="\${PWD}"
# Add git branch if available. # Add git branch if available.
local git_branch="$(_git_current_branch)" if ! _git_is_dotfiles; then
if [[ "${git_branch}" != "" ]]; then local git_branch="$(_git_current_branch)"
[[ "${git_branch}" =~ (master|main) ]] || PS1+=" ${color_bblue}@${git_branch}" if [[ "${git_branch}" != "" ]]; then
PS1+=" ${color_bblue}@${git_branch}"
fi
fi fi
# set error red # set error red