-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_prompt
103 lines (88 loc) · 2.76 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
# Requirements:
# 1. A 24-bit-color-capable terminal (e.g., iTerm)
# 2. A font patched by Nerd Fonts (https://www.nerdfonts.com/)
# 3. The `__git_ps1` Bash function (macOS: `source /usr/local/etc/bash_completion.d/git-prompt.sh`)
if [ -z $PROMPT_SEPARATOR_CHARACTER ]; then
__prompt_separator_character=">"
else
__prompt_separator_character=$PROMPT_SEPARATOR_CHARACTER
fi
if [ -z $PROMPT_LOGO ]; then
__prompt_logo="*"
else
__prompt_logo=$PROMPT_LOGO
fi
if [ $(uname) == "Darwin" ]; then
__prompt_hostname=$(scutil --get LocalHostName)
else
__prompt_hostname=$(hostname -s)
fi
__prompt_blue="[38;2;97;175;239m"
__prompt_green="[38;2;140;197;111m"
__prompt_grey="[38;2;127;132;142m"
__prompt_orange="[38;2;209;154;102m"
__prompt_reset="\e[m"
__prompt_main_color () {
if [ -z $PROMPT_MAIN_COLOR_CODE ]; then
echo -e "\x1b$__prompt_green"
else
echo -e "\x1b$PROMPT_MAIN_COLOR_CODE"
fi
}
__prompt_separator () {
echo -e " \x1b[38;2;92;99;112m$__prompt_separator_character\x1b[m "
}
__prompt_git_status () {
__git_status=$(git status --porcelain=v2 2>/dev/null)
if [ -z "$__git_status" ]; then
echo -e "\x1b${__prompt_grey}\x1b[m"
else
echo -e "\x1b${__prompt_green}\x1b[m"
fi
}
# TODO: Check if an upstream exists
__prompt_git_ahead_behind () {
__local_ref=$(git rev-parse @)
__remote_ref=$(git rev-parse @{u} 2>/dev/null)
__merge_base=$(git merge-base @ @{u} 2>/dev/null)
if ([ -z "$__remote_ref" ] && [ -z "$__merge_base"]) || [ "$__local_ref" = "$__remote_ref" ]; then
return
fi
if [ $__local_ref = $__merge_base ]; then
echo -e " \x1b${__prompt_green}\x1b[m"
elif [ $__remote_ref = $__merge_base ]; then
echo -e " \x1b${__prompt_green}\x1b[m"
else
echo -e " \x1b${__prompt_orange}\x1b[m"
fi
}
__prompt_git () {
__git_branch=$(__git_ps1 "(%s)")
if [ -n "$__git_branch" ]; then
echo -e "$(__prompt_separator)$__git_branch $(__prompt_git_status)$(__prompt_git_ahead_behind)"
fi
}
# Prompt parts:
# username + $__prompt_logo + host...
# then the current directory (\w)...
# then Git status, if applicable...
# then a newline followed by "$ " or "# "
export PS1="\n$(__prompt_main_color)[\u \e$__prompt_grey$__prompt_logo$(__prompt_main_color) $__prompt_hostname]$(__prompt_separator)\w\$(__prompt_git)\n\$ "
# One Dark theme colors
# background: 39;44;53
# grey: 127;132;142
# grey1: 32;37;44
# grey2: 43;49;61
# grey3: 62;72;91
# grey4: 92;99;112
# grey5: 169;178;192
# tan: 109;113;112
# red: 244;71;71
# coral: 224;108;117
# orange: 209;154;102
# yellow: 229;192;123
# green: 140;197;111
# green1: 152;195;121
# bluegreen: 86;182;194
# blue: 97;175;239
# purple: 198;120;221