-
Notifications
You must be signed in to change notification settings - Fork 3
/
.bashrc
110 lines (95 loc) · 2.79 KB
/
.bashrc
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
# don't do anything if not running interactively
case $- in
*i*) ;; # interactive
*)
if [ -f ~/.bashrc_overrides ]
then
. ~/.bashrc_overrides
fi
return;; # non-interactive
esac
# load `~/.profile` in nonlogin mode
if [ -f ~/.profile ]
then
. ~/.profile rc
fi
# Bash settings
shopt -s checkwinsize
shopt -s histappend
set_prompt() {
# constants
local begin='\[\e['
local end='m\]'
local pwd='\w'
# foreground (fg): 30 to 37
# background (bg): 40 to 47
# weight: 0 [normal] or 1 [bold]
local weight=1
local primary_bg=47
local user='\u'
local hostname=' :3'
local prompt='\$'
# current Git branch
local git_cmd='git 2>/dev/null rev-parse --abbrev-ref HEAD'
local branch='$(b=`'"$git_cmd"'` && echo "($b) " || :)'
# don't use bold in the Linux terminal because it looks bad
if [ "$TERM" = linux ]; then
weight=0
fi
# hide hostname on some systems and use color instead
hostname_to_color "$HOSTNAME"
unset -f hostname_to_color
case $host_color in
black) primary_bg=40;;
red) primary_bg=41;;
green) primary_bg=42;;
yellow) primary_bg=43;;
blue) primary_bg=44;;
magenta) primary_bg=45;;
cyan) primary_bg=46;;
white) primary_bg=47;;
*) hostname='@\h';;
esac
# change color based on username
if [[ "$USER" = root ]]; then
primary_bg=41
user=
hostname='@\h'
prompt='#'
fi
# disable Git branch on Windows because it's slooow
case $OSTYPE in
cygwin) branch=; hostname='[cygwin]';;
msys) branch=; hostname='[msys]';;
esac
local primary_fg=$((primary_bg - 10))
PS1=
PS1+="${begin}$weight;30;$primary_bg${end} $user$hostname "
PS1+="${begin}37;49${end} $branch"
PS1+="${begin}$primary_fg${end}$pwd"
PS1+="${begin}${end}\n" # weird things can happen if newline is colored
PS1+="${begin}$weight;$primary_fg${end}$prompt${begin}${end} "
PS2="${begin}$weight;$primary_fg${end}|${begin}${end} "
PS3="${begin}$weight;$primary_fg${end}?${begin}${end} "
PS4="${begin}$weight;$primary_fg${end}|${begin}${end} "
} && set_prompt; unset -f set_prompt
# enable auto-completion if not already enabled
case $OSTYPE in
cygwin|msys);;
*)
if ! shopt -oq posix
then
if [ -f /usr/share/bash-completion/bash_completion ]
then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]
then
. /etc/bash_completion
fi
fi
;;
esac
if [ -f ~/.bashrc_overrides ]
then
. ~/.bashrc_overrides
fi