-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_prompt
124 lines (108 loc) · 5.17 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
__powerline() {
# colorscheme
readonly FG_BLACK="\[$(tput setaf 0)\]"
readonly FG_RED="\[$(tput setaf 1)\]"
readonly FG_GREEN="\[$(tput setaf 2)\]"
readonly FG_YELLOW="\[$(tput setaf 3)\]"
readonly FG_BLUE="\[$(tput setaf 4)\]"
readonly FG_MAGENTA="\[$(tput setaf 5)\]"
readonly FG_CYAN="\[$(tput setaf 6)\]"
readonly FG_WHITE="\[$(tput setaf 7)\]"
readonly BG_BLACK="\[$(tput setab 0)\]"
readonly BG_RED="\[$(tput setab 1)\]"
readonly BG_GREEN="\[$(tput setab 2)\]"
readonly BG_YELLOW="\[$(tput setab 3)\]"
readonly BG_BLUE="\[$(tput setab 4)\]"
readonly BG_MAGENTA="\[$(tput setab 5)\]"
readonly BG_CYAN="\[$(tput setab 6)\]"
readonly BG_WHITE="\[$(tput setab 7)\]"
readonly DIM="\[$(tput dim)\]"
readonly REVERSE="\[$(tput rev)\]"
readonly RESET="\[$(tput sgr0)\]"
readonly BOLD="\[$(tput bold)\]"
# Unicode symbols
readonly GIT_PROMPT_SYMBOL_BRANCH='➦'
readonly GIT_PROMPT_SYMBOL_ADD="${FG_WHITE}Ⓐ ${RESET}"
readonly GIT_PROMPT_SYMBOL_DELETE="${FG_RED}Ⓓ ${RESET}"
readonly GIT_PROMPT_SYMBOL_MODIFY="${FG_MAGENTA}Ⓜ ${RESET}"
readonly GIT_PROMPT_SYMBOL_RENAME="${FG_CYAN}Ⓡ ${RESET}"
readonly GIT_PROMPT_SYMBOL_COMMIT="${FG_YELLOW}Ⓒ ${RESET}"
readonly GIT_PROMPT_SYMBOL_PUSH="⬆"
readonly GIT_PROMPT_SYMBOL_PULL="⬇"
readonly SYSTEM_PROMPT_SYMBOL_TRUE='✔'
readonly SYSTEM_PROMPT_SYMBOL_FALSE='✘'
readonly SYSTEM_PROMPT_SYMBOL_JOBS='⚙'
readonly SYSTEM_PROMPT_SYMBOL_ROOT='⚡'
readonly SYSTEM_PROMPT_SYMBOL_AT='@'
readonly SYSTEM_PROMPT_SYMBOL_USER='➜'
readonly SYSTEM_PROMPT_SYMBOL_SEPARATOR=''
__git_info() {
if [ ! -x "$(which git)" ]; then
printf "${FG_BLUE}${SYSTEM_PROMPT_SYMBOL_SEPARATOR}${RESET}"
return # git not found
fi
# get current branch name or short SHA1 hash for detached head
local BRANCH="$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --always 2>/dev/null)"
if [ ! -n "$BRANCH" ]; then
printf "${FG_BLUE}${SYSTEM_PROMPT_SYMBOL_SEPARATOR}${RESET}"
return # git branch not found
fi
local INDEX=$(command git status --porcelain -b 2> /dev/null)
local STATUS=""
local GIT_PROMPT_SYMBOL
local stat="$(echo $INDEX | grep '^##' | grep -o '\[.\+\]$')"
local aheadN="$(echo $stat | grep -o 'ahead \d\+' | grep -o '\d\+')"
local behindN="$(echo $stat | grep -o 'behind \d\+' | grep -o '\d\+')"
if [ -n "$behindN" ]; then
STATUS="$GIT_PROMPT_SYMBOL_PULL $behindN$STATUS"
fi
if [ -n "$aheadN" ]; then
STATUS="$GIT_PROMPT_SYMBOL_PUSH $aheadN$STATUS"
fi
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_COMMIT$STATUS"
elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_COMMIT$STATUS"
fi
if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_RENAME$STATUS"
fi
if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_MODIFY$STATUS"
elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_MODIFY$STATUS"
elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_MODIFY$STATUS"
fi
if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_DELETE$STATUS"
elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_DELETE$STATUS"
elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_DELETE$STATUS"
fi
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
STATUS="$GIT_PROMPT_SYMBOL_ADD$STATUS"
fi
if [ -n "${STATUS}" ]; then
GIT_PROMPT_SYMBOL="${BG_YELLOW}${FG_BLUE}${SYSTEM_PROMPT_SYMBOL_SEPARATOR} ${FG_BLACK}${GIT_PROMPT_SYMBOL_BRANCH}${BRANCH} ${STATUS} ${RESET}${FG_YELLOW}${SYSTEM_PROMPT_SYMBOL_SEPARATOR}${RESET}"
else
GIT_PROMPT_SYMBOL="${BG_GREEN}${FG_BLUE}${SYSTEM_PROMPT_SYMBOL_SEPARATOR} ${FG_BLACK}${GIT_PROMPT_SYMBOL_BRANCH}${BRANCH} ${RESET}${FG_GREEN}${SYSTEM_PROMPT_SYMBOL_SEPARATOR}${RESET}"
fi
printf "${GIT_PROMPT_SYMBOL}"
}
ps1() {
local RETVAL=$?
local PROMPT_SYMBOL
local PROMPT_SYMBOL_DIR="${BG_BLUE}${FG_BLACK} \w ${RESET}"
[[ $RETVAL -ne 0 ]] && PROMPT_SYMBOL+="${BG_BLACK}${FG_RED}${SYSTEM_PROMPT_SYMBOL_FALSE} ${RESET}"
[[ $(jobs -l | wc -l) -gt 0 ]] && PROMPT_SYMBOL+="${BG_BLACK}${FG_CYAN}${SYSTEM_PROMPT_SYMBOL_JOBS} ${RESET}"
[[ $UID -eq 0 ]] && PROMPT_SYMBOL+="${BG_BLACK}${FG_YELLOW}${SYSTEM_PROMPT_SYMBOL_ROOT} \u${SYSTEM_PROMPT_SYMBOL_AT}\h ${RESET}"
[[ -n "${PROMPT_SYMBOL}" ]] && PROMPT_SYMBOL="${BG_BLACK} ${PROMPT_SYMBOL}${BG_BLUE}${FG_BLACK}${SYSTEM_PROMPT_SYMBOL_SEPARATOR}${RESET}"
PS1="${PROMPT_SYMBOL}${PROMPT_SYMBOL_DIR}$(__git_info) "
}
PROMPT_COMMAND=ps1
}
__powerline
unset __powerline