-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_prompt
62 lines (47 loc) · 1.82 KB
/
.bash_prompt
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
#!/bin/bash
prompt_git() {
local s=""
local branchName=""
# check if the current directory is in a git repository
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 0 ]; then
# check if the current directory is in .git before running git checks
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
# ensure 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
s="$s+";
fi
# check for unstaged changes
if ! $(git diff-files --quiet --ignore-submodules --); then
s="$s!";
fi
# check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
s="$s?";
fi
# check for stashed files
if $(git rev-parse --verify refs/stash &>/dev/null); then
s="$s$";
fi
fi
# get the short symbolic ref
# if HEAD isn't a symbolic ref, get the short SHA
# otherwise, just give up
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
printf "(unknown)")"
[ -n "$s" ] && s="[$s]"
printf "%s" "($branchName)$s"
else
return
fi
}
PS1="\[\033[38;5;196m\]\u" # username
PS1+="\[\033[38;5;246m\]@"
PS1+="\[\033[38;5;230m\]\h" # host
PS1+="\[\033[38;5;246m\]:"
PS1+="\[\033[38;5;166m\]\W" # working directory
PS1+="\[\033[38;5;221m\]\$(prompt_git)" # git repo info
PS1+="\[\033[38;5;136m\]\\$ \[\033[38;5;15m\]" # $ and reset color
export PS1