-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-prompt_tput.sh
44 lines (34 loc) · 1.31 KB
/
bash-prompt_tput.sh
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
# prompt - tput
#
# bash prompt with exit status and git head
#
# https://github.com/linuxCowboy/prompt
#
# color hint:
# 0-black 1-red 2-green 3-brown [yellow] 4-blue 5-purple [magenta] 6-cyan 7-white
PS1='$(i=$?
echo -ne "\[$(tput sgr0)\]"
echo -ne "\[$(tput setaf 3)\]\! " # history
echo -ne "\[$(tput setaf 5)\]\j " # jobs
echo -ne "\[$(tput setaf 4)\]\h:" # host
echo -ne "${PWD//\//\[$(tput bold;tput setaf 4)\]/\[$(tput sgr0;tput setaf 2)\]}" # path
((i)) && echo -n "\[$(tput bold;tput setaf 1)\][$i]" # exit code
G=`git rev-parse --is-inside-work-tree 2>/dev/null`
if ((! $?)); then
H=`git symbolic-ref --short --quiet HEAD ||
git rev-parse --short HEAD`
F=
if [[ $G = true ]]; then
S=`git --no-optional-locks status --porcelain |
cut --bytes 1-2`
echo "$S" |grep -q "^[MTADRCU]" && F+="I" # indexed
echo "$S" |grep -q "[MTADRCU]\$" && F+="M" # modified
[[ $S =~ \? ]] && F+="U" # untracked
echo -ne "\[$(tput bold;tput setaf 6)\] {$H}\[$(tput setaf 3)\]${F:+ $F}" # head
else
echo -ne "\[$(tput bold;tput setaf 0)\] {$H}" # in .git/
fi
fi
sleep 0.1 # fix for bg jobs
echo -ne "\[$(tput sgr0)\] \$ " # uid
)'