-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.shell
More file actions
110 lines (98 loc) · 4.27 KB
/
Copy pathplugin.shell
File metadata and controls
110 lines (98 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
################################################################################
# Plugin : bash-git
# Author : Justin Francis
# (c) Copyright 2012
# Created : March 3, 2012
# Source URL : https://github.com/comwt/bash-git
#
# Purpose : Provides a Git information bar (info bar) when you are under
# a git repository. It displays the following information:
# - current branch (in 'red' if on main or master)
# - current cksum (in 'red' if there are uncommitted changes
# and displays an 'uncommitted changes' message in the message
# area)
# - stash count in the message area if you have stashes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
################################################################################
function Func_GitCheck {
l_git_branch=$(__git_ps1 | awk -F\( '{print $2}' | awk -F\) '{print $1}')
if [[ ${l_git_branch} == "" ]]; then
return
fi
l_hlt="\033[30;47m" #(highlight) white background/black foreground
l_inf="\033[31m" #(message info) red foreground
l_int="\033[1m" #(intensity) intensifies foreground
l_blufg="\033[34;47m" #(normal info) blue foreground
l_blubg="\033[37;44m" #(normal info) blue background
l_maj="\033[41;37m" #(major info) red background/white foreground
l_rst="\033[m" #(reset) original terminal colors
l_msg=
if [[ ${l_git_branch} == "main" || ${l_git_branch} == "master" || ${l_git_branch} == "GIT_DIR!" ]]; then
l_git_branch="${l_maj}${l_git_branch}${l_hlt}"
else
l_git_branch="${l_blufg}${l_git_branch}${l_hlt}"
fi
l_git_sha1=$(git branch --verbose 2>/dev/null|awk '$1 == "*" {print $3}')
if [[ ${l_git_sha1} == "" ]]; then
l_git_sha1 = 'stateless'
fi
#- If you need more speedy responses on large repositories, this is where
# you need to look. git status takes much longer than the other commands.
#- The --porcelain option to 'git status' was added in version 1.7.0.
#---------------------------------------------------------------------------
git version 2>/dev/null | grep -c -E "version (0|1\.[0123456])" 1>/dev/null 2>&1
l_use_porcelain_TF=$?
if [[ ${l_use_porcelain_TF} ]]; then
l_changes=$(git status --porcelain 2>/dev/null | wc -l)
else
l_changes=$(git status 2>/dev/null | awk '/^#\t/ {print}' 2>/dev/null | wc -l)
fi
if [[ ${l_changes} -ne 0 ]]; then
l_git_sha1="${l_maj}${l_git_sha1}${l_hlt}"
l_msg="${l_msg} / ${l_changes} uncommitted"
if [[ ${l_changes} -eq 1 ]]; then
l_msg="${l_msg} change"
else
l_msg="${l_msg} changes"
fi
else
l_git_sha1="${l_blufg}${l_git_sha1}${l_hlt}"
fi
l_msg="${l_inf}${l_msg}"
l_stash=$(git stash list 2>&1 3>&1)
if [[ $(echo ${l_stash} | grep -c "fatal.*working tree") -eq 0 && $l_stash != "" ]]; then
l_stash_cnt=$(echo ${l_stash} | wc -l | awk '{print $NF}')
if [[ ${l_stash_cnt} -gt 0 ]]; then
l_msg="${l_msg} / ${l_int}${l_blubg}STASHES: ${l_stash_cnt}${l_blufg}"
fi
fi
#- Print the 'Info Bar'
#-----------------------
l_columns=
if [[ ${COLUMNS} != "" ]]; then
l_columns=${COLUMNS}
else
l_columns=0
fi
echo
if [[ ! ${OS} ]]; then
printf "${l_hlt}"; printf -vch "%${COLUMNS}s" "" 2>/dev/null; printf "%s" "${ch// / }"; printf "${l_rst}\r"
fi
printf "${l_hlt} ${l_int}BRANCH:${l_rst}${l_hlt} ${l_git_branch} (${l_git_sha1})${l_msg} ${l_rst}\n\$ "
}
export COLUMNS
PS1="${PS1}\$(Func_GitCheck)"