PS1 : show git branch when not in dotfiles.
This commit is contained in:
parent
8bd6946470
commit
b7d4c77088
|
@ -87,6 +87,37 @@ _git_current_branch()
|
|||
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.
|
||||
_completion_loader git &> /dev/null
|
||||
__git_complete gps _git_push &> /dev/null
|
||||
|
|
|
@ -44,9 +44,11 @@ __prompt_command()
|
|||
# PS1+="\${PWD}"
|
||||
|
||||
# Add git branch if available.
|
||||
local git_branch="$(_git_current_branch)"
|
||||
if [[ "${git_branch}" != "" ]]; then
|
||||
[[ "${git_branch}" =~ (master|main) ]] || PS1+=" ${color_bblue}@${git_branch}"
|
||||
if ! _git_is_dotfiles; then
|
||||
local git_branch="$(_git_current_branch)"
|
||||
if [[ "${git_branch}" != "" ]]; then
|
||||
PS1+=" ${color_bblue}@${git_branch}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# set error red
|
||||
|
|
Reference in a new issue