blob: 35a182ab6f9f7ff84eb79d2a47052a1167fc3cb7 (
plain)
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
|
function parse_git_branch {
git rev-parse --is-inside-work-tree &>/dev/null || return
local branch=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null)
echo "(${branch})"
}
## ✗ ✓ ↑ ↓ ↲ ↲ ↳ ↴ ↵ ↺ ➔ ➙ ➜ ➥
function parse_git_status {
local symbol="✓" # clean state (up to date)
if git rev-parse --is-inside-work-tree &>/dev/null; then
local branch
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
# Ahead / behind remote
if [[ "$branch" != "HEAD" ]]; then
local behind=$(git rev-list --count HEAD..origin/$branch 2>/dev/null || echo 0)
local ahead=$(git rev-list --count origin/$branch..HEAD 2>/dev/null || echo 0)
if [[ "$ahead" -gt 0 ]]; then
symbol="↑"
elif [[ "$behind" -gt 0 ]]; then
symbol="↓"
fi
fi
# Unstaged changes
if ! git diff --quiet 2>/dev/null; then
symbol="✗"
fi
if ! git diff --cached --quiet 2>/dev/null; then
symbol="✗"
fi
# untracked files
if git ls-files --others --exclude-standard -z | grep -q .; then
symbol="?"
fi
fi
echo "${symbol}"
}
function set_PS1 {
WHITE="\[\033[01;015m\]"
YELLOW="\[\033[01;33m\]"
BLUE="\[\033[01;34m\]"
RED="\[\033[01;31m\]"
PINK="\[\033[01;35m\]"
RESET="\[\033[0m\]"
if git rev-parse --is-inside-work-tree &>/dev/null; then
PS1="${YELLOW}\u@\h ${BLUE}[$(basename "$PWD")]${RED}$(parse_git_branch) ${RESET}$(parse_git_status) ${PINK}\$:${RESET} "
else
PS1="${WHITE}\u@\h \$: ${RESET}"
#PS1="\[\033[01;015m\]\u@\h $: \[\033[0m\]"
fi
}
set_PS1
PROMPT_COMMAND=set_PS1
|