some recoloring and rework of the git prompt
This commit is contained in:
parent
077a4088a7
commit
e38c92d37f
1 changed files with 13 additions and 11 deletions
24
bashplugins
24
bashplugins
|
@ -25,35 +25,37 @@ gdf()
|
||||||
|
|
||||||
git_prompt()
|
git_prompt()
|
||||||
{
|
{
|
||||||
|
local staged_count unstaged_count untracked_count unmerged_count
|
||||||
|
local git_status branch_info full_status IFS=
|
||||||
|
|
||||||
prompt_command
|
prompt_command
|
||||||
|
|
||||||
if ! raw_status="$(git status --porcelain -bu 2>/dev/null)"; then
|
if ! raw_status="$(git status --porcelain -bu 2>/dev/null)"; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git_status=''
|
git_status=''
|
||||||
staged_count=0
|
staged_count=0
|
||||||
unstaged_count=0
|
unstaged_count=0
|
||||||
untracked_count=0
|
untracked_count=0
|
||||||
unmerged_count=0
|
unmerged_count=0
|
||||||
|
|
||||||
local IFS=
|
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
if [[ "${line:0:2}" == '##' ]]; then
|
[[ "${line:0:2}" == '##' ]] && branch_info="${line:3}"
|
||||||
read branch_info <<< "${line:3}"
|
|
||||||
fi
|
|
||||||
[[ "${line:0:2}" =~ .[MD] ]] && (( unstaged_count++ ))
|
[[ "${line:0:2}" =~ .[MD] ]] && (( unstaged_count++ ))
|
||||||
[[ "${line:0:2}" =~ [MDARC]. ]] && (( staged_count++ ))
|
[[ "${line:0:2}" =~ [MDARC]. ]] && (( staged_count++ ))
|
||||||
[[ "${line:0:2}" == '??' ]] && (( untracked_count++ ))
|
[[ "${line:0:2}" == '??' ]] && (( untracked_count++ ))
|
||||||
[[ "${line:0:2}" =~ (U[ADU]|A[AU]|D[DU]) ]] && (( unmerged_count++ ))
|
[[ "${line:0:2}" =~ (U[ADU]|A[AU]|D[DU]) ]] && (( unmerged_count++ ))
|
||||||
done <<< "${raw_status}"
|
done <<< "${raw_status}"
|
||||||
|
|
||||||
(( $unstaged_count > 0 )) && git_status+="${pmagenta}~${unstaged_count}"
|
(( $unstaged_count > 0 )) && git_status+="${ppurple}~${unstaged_count}"
|
||||||
(( $staged_count > 0 )) && git_status+="${pgreen}+${staged_count}"
|
(( $staged_count > 0 )) && git_status+="${pblue}+${staged_count}"
|
||||||
(( $untracked_count > 0 )) && git_status+="${pyellow}-${untracked_count}"
|
(( $untracked_count > 0 )) && git_status+="${pred}-${untracked_count}"
|
||||||
(( $unmerged_count > 0 )) && git_status+="${pred}*${unmerged_count}"
|
(( $unmerged_count > 0 )) && git_status+="${porange}*${unmerged_count}"
|
||||||
[[ -z "${git_status}" ]] && git_status='.'
|
[[ -z "${git_status}" ]] && git_status="${pgreen}ok"
|
||||||
|
|
||||||
|
full_status="{ ${pgray3}${branch_info}${preset} | ${git_status}${preset} }"
|
||||||
|
|
||||||
full_status="{ ${pblue}${branch_info}${preset} | ${git_status}${preset} }"
|
|
||||||
if [[ -n "${OLD_PROMPT}" ]]; then
|
if [[ -n "${OLD_PROMPT}" ]]; then
|
||||||
PS1="${ps_line1} ${full_status}\n${ps_line2}"
|
PS1="${ps_line1} ${full_status}\n${ps_line2}"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue