-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_config.sh
50 lines (43 loc) · 1.18 KB
/
bash_config.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
# Define some base colors
bold_red="\[\e[01;31m\]"
bold_green="\[\e[01;32m\]"
bold_orange="\[\e[01;33m\]"
bold_blue="\[\e[01;34m\]"
bold_purple="\[\e[01;35m\]"
bold_cyan="\[\e[01;36m\]"
red="\[\e[31m\]"
green="\[\e[32m\]"
orange="\[\e[33m\]"
blue="\[\e[34m\]"
purple="\[\e[35m\]"
cyan="\[\e[36m\]"
clear="\[\e[00m\]"
# Map colors to parts of prompt
color_user=$green
color_at_symbol=$blue
color_host=$green
color_pwd=$orange
color_jobs=$purple
color_prompt_symbol=$green
color_git_branch=$cyan
# If user is root, update some of these mappings
if [ $(id -u) -eq 0 ]; then
color_user=$red
color_host=$red
color_at_symbol=$orange
color_pwd=$orange
fi
# Build background jobs summary section
__ps1_get_jobs() {
jobs_output=`jobs`
if [ "$jobs_output" ]; then
echo -e "${color_jobs}$jobs_output\\\n"
fi
}
# Safely get the git branch (only if the function is defined)
__ps1_get_git_branch() {
declare -F -f __git_ps1 > /dev/null && __git_ps1
}
# Define prompt command to build PS1 on demand
PROMPT_COMMAND='__ps1_exit_code=$?;PS1="\n`__ps1_get_jobs;`${color_user}\u${color_at_symbol}@${color_host}\h${clear} ${color_pwd}\w${color_git_branch}`__ps1_get_git_branch`
${color_prompt_symbol}\$${clear} "'