-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashprompt
48 lines (41 loc) · 1.42 KB
/
.bashprompt
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
# Git highlighting from http://noqqe.de/blog/2012/03/10/git-shell-environment-tricks/
BOLD="\[\033[1m\]"
RED="\[\033[1;31m\]"
GREEN="\[\033[1;32m\]"
YELLOW="\[\033[1;33m\]"
BLUE="\[\033[1;34m\]"
OFF="\[\033[m\]"
GIT_THEME_PROMPT_DIRTY="${RED}*${OFF}"
GIT_THEME_PROMPT_UNPUSHED="${YELLOW}+${OFF}"
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo -e " (${ref#refs/heads/}$(parse_git_dirty))"
}
function parse_git_dirty {
if [[ -n $(git status -s 2> /dev/null |grep -v ^# | grep -v "working directory clean" ) ]]; then
echo -n "${GIT_THEME_PROMPT_DIRTY}"
else
echo -n "${GIT_THEME_PROMPT_CLEAN}"
fi
GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD)
GIT_ORIGIN_UNPUSHED=$(git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline 2>&1 | awk '{ print $1 }')
if [[ $GIT_ORIGIN_UNPUSHED != "" ]]; then
echo "${GIT_THEME_PROMPT_UNPUSHED}"
else
echo "${GIT_THEME_PROMPT_CLEAN}"
fi
}
function myprompt {
EXITSTATUS="$?"
STOPPED="$(jobs -s | wc -l | tr -d " ")"
RUNNING="$(jobs -r | wc -l | tr -d " ")"
CUR_TTY=$(tty | sed -e "s/.*pts\(.*\)/\1/")
JOBS=${RUNNING}/${STOPPED}
if [ "$EXITSTATUS" -eq "0" ]; then
PS1="${GREEN}\u@\h[${JOBS}]${OFF}:${BLUE}\w${OFF}\[$(git_prompt_info)\]${OFF}\\n\$${OFF} "
else
PS1="${GREEN}\u@\h[${JOBS}]${OFF}:${BLUE}\w${OFF}\[$(git_prompt_info)\]${OFF}${RED}\\n\$${OFF} "
fi
PS2="${BOLD}> ${OFF} "
}
PROMPT_COMMAND=myprompt