-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.prompt.sh
93 lines (77 loc) · 2.3 KB
/
.prompt.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
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
#!/usr/bin/env bash
function prompt_git() {
local branchname='';
local on=${1:-"${white} on ${violet}"}
local statuscolor=${2:-"${blue}"}
local status='';
# check if the current directory is in a git repository
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then
# check if the current directory is in .git before running checks
if [ "$(git rev-parse --is-inside-git-dir 2>/dev/null)" == 'false' ]; then
# ensures the index is up to date
git update-index --really-refresh -q &>/dev/null;
# check for uncommitted changes in the index
if ! $(git diff --quiet --ignore-submodules --cached); then
status+='+';
fi;
# check for unstaged changes
if ! $(git diff-files --quiet --ignore-submodules --); then
status+='!';
fi
# check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
status+='?';
fi;
# check for stashed files
if $(git rev-parse --verify refs/stash &>/dev/null); then
status+='$';
fi
fi
# get the short symbolic ref.
# if HEAD isn't a symbolic ref, get the short SHA for the latest commit
# otherwise, just give up
branchname="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || \
git rev-parse --short HEAD 2>/dev/null || \
echo '(unknown)')";
# ... or simply do
# branchname="$(git branch 2>/dev/null | grep '^*' | colrm 1 2)"
[ -n "${status}" ] && status=" [${status}]";
echo -e "${on}${branchname}${statuscolor}${status}";
else
return;
fi
}
if [[ $(tput longname 2>/dev/null) ]]; then
# Solarized colors, taken from http://git.io/solarized-colors.
tput sgr0; # reset
orange=$(tput setaf 166);
yellow=$(tput setaf 228);
red=$(tput setaf 124);
green=$(tput setaf 71);
violet=$(tput setaf 61);
blue=$(tput setaf 33);
white=$(tput setaf 15);
gray=$(tput setaf 242);
bold=$(tput bold);
reset=$(tput sgr0);
fi
if [[ "${USER}" == "root" ]]; then
usercolor="${red}";
else
usercolor="${orange}";
fi
PS1="\n";
PS1+="\[${gray}\]\[\e(0\]lq\[\e(B\] ";
PS1+="\[${bold}\]\[\${usercolor}\]\u";
PS1+="\[${white}\] at ";
PS1+="\[${yellow}\]\h";
PS1+="\[${white}\] in ";
PS1+="\[${green}\]\W";
PS1+="\$(prompt_git)"
PS1+="\n";
PS1+="\[${gray}\]\[\e(0\]mq\[\e(B\] ";
PS1+="\[${white}\]\$ ";
PS1+="\[${reset}\]"
export PS1;
PS2="\[${white}\]→ \[${reset}\]";
export PS2;