From 125ef0af69a95236b44ee07842b8d7e00e74cb3a Mon Sep 17 00:00:00 2001 From: home Date: Mon, 27 Nov 2023 21:18:55 +0300 Subject: [PATCH] PS1 : add git branch. --- .config/bash/module/git.sh | 6 ++++++ .config/bash/module/ps1.sh | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.config/bash/module/git.sh b/.config/bash/module/git.sh index e4294cc..4f9c615 100644 --- a/.config/bash/module/git.sh +++ b/.config/bash/module/git.sh @@ -74,6 +74,12 @@ gg() git clone https://git.voronind.com/voronind/"${1}" } +# Show current branch. +_git_current_branch() +{ + git branch --show-current 2> /dev/null +} + # autocomplete. _completion_loader git &> /dev/null __git_complete gps _git_push &> /dev/null diff --git a/.config/bash/module/ps1.sh b/.config/bash/module/ps1.sh index 52e1098..c177733 100644 --- a/.config/bash/module/ps1.sh +++ b/.config/bash/module/ps1.sh @@ -40,8 +40,12 @@ __prompt_command() # add user, host and working dir PS1+="\u@\h " PS1+="\[${color_blue}\]" - PS1+="\w" - # PS1+="\${PWD}" + # PS1+="\w" + PS1+="\${PWD}" + + # Add git branch if available. + local git_branch="$(_git_current_branch)" + [[ "${git_branch}" = "" ]] || PS1+=" ${color_blue}@${git_branch}" # set error red if $is_error; then