-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_prompt
137 lines (108 loc) Β· 2.88 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
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
#
# bash-prompt
#
# Improved bash prompt with support for Git.
# github.com/sblaurock/bash-prompt
# v1.1
#
# Define colors
COLOR_DEFAULT='\[\e[39m\]'
COLOR_RED='\[\e[31m\]'
COLOR_GREEN='\[\e[32m\]'
COLOR_YELLOW='\[\e[33m\]'
COLOR_BLUE='\[\e[34m\]'
COLOR_MAGENTA='\[\e[35m\]'
COLOR_CYAN='\[\e[36m\]'
COLOR_LIGHT_GRAY='\[\e[37m\]'
COLOR_GRAY='\[\e[90m\]'
COLOR_LIGHT_RED='\[\e[91m\]'
COLOR_LIGHT_GREEN='\[\e[92m\]'
COLOR_LIGHT_YELLOW='\[\e[93m\]'
COLOR_LIGHT_BLUE='\[\e[94m\]'
COLOR_LIGHT_MAGENTA='\[\e[95m\]'
COLOR_LIGHT_CYAN='\[\e[96m\]'
COLOR_WHITE='\[\e[97m\]'
# Options
SHOW_USERNAME=true
SHOW_HOSTNAME=false
NAME_DIVIDER="@"
USERNAME_COLOR=$COLOR_LIGHT_RED
HOSTNAME_COLOR=$COLOR_LIGHT_MAGENTA
NAME_DIVIDER_COLOR=$COLOR_LIGHT_MAGENTA
SHOW_CWD=true
FULL_CWD=false
CWD_COLOR=$COLOR_GREEN
SHOW_GIT=true
SHOW_GIT_DIRTY=true
GIT_DIRTY_SYMBOL=" *"
GIT_DIRTY_COLOR=$COLOR_LIGHT_RED
WRAP_BRANCH=false
WRAP_BRANCH_SYMBOLS="[]"
GIT_COLOR=$COLOR_RED
SPACER="@"
SPACER_COLOR=$COLOR_LIGHT_CYAN
SYMBOL=" "
SYMBOL_COLOR=$COLOR_LIGHT_MAGENTA
# Return the current Git branch name (or false)
function git_branch() {
local branch="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
if [ ! -z $branch ]; then
echo $branch
fi
}
# Are we in a Git repository?
function on_git() {
if $(git rev-parse --is-inside-work-tree 2> /dev/null); then
return 0
fi
return 1
}
# Is our Git branch dirty?
function git_dirty() {
if $(git diff-index --quiet HEAD 2> /dev/null); then
return 1
fi
return 0
}
# Set the spacer based on whether or not group is first to be displayed
firstItem=true
function get_spacer() {
$firstItem && spacer='' || spacer="${SPACER_COLOR}${SPACER}${SPACER_COLOR}"
firstItem=false
}
# Sets bash prompt based on the values defined within options
function set_ps1() {
if $SHOW_USERNAME || $SHOW_HOSTNAME ; then
get_spacer
if $SHOW_USERNAME && $SHOW_HOSTNAME ; then
local divider=${NAME_DIVIDER_COLOR}${NAME_DIVIDER}${COLOR_DEFAULT}
fi
if $SHOW_USERNAME ; then
local username=${USERNAME_COLOR}"\u"${COLOR_DEFAULT}
fi
if $SHOW_HOSTNAME ; then
local hostname=${HOSTNAME_COLOR}"\h"${COLOR_DEFAULT}
fi
local name=${spacer}${username}${divider}${hostname}
fi
if $SHOW_CWD ; then
get_spacer
$FULL_CWD && cwdType="\w" || cwdType="\${PWD#\${PWD%/*/*}}"
local cwd=${spacer}${CWD_COLOR}${cwdType}${COLOR_DEFAULT}
fi
if $SHOW_GIT ; then
get_spacer
if $SHOW_GIT_DIRTY ; then
local dirty=${GIT_DIRTY_COLOR}${GIT_DIRTY_SYMBOL}${COLOR_DEFAULT}
fi
if $WRAP_BRANCH ; then
local git=" "${GIT_COLOR}${WRAP_BRANCH_SYMBOLS:0:1}"\$(git_branch)"${WRAP_BRANCH_SYMBOLS:1:2}${COLOR_DEFAULT}
else
local git=${spacer}${GIT_COLOR}"\$(git_branch)"${COLOR_DEFAULT}
fi
fi
local symbol=${SYMBOL_COLOR}${SYMBOL}${COLOR_DEFAULT}
echo "${name}${cwd}\$(on_git && echo \"${git}\"\$(git_dirty && echo \"${dirty}\"))${symbol}"
}
export PS1=$(set_ps1)