-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
232 lines (190 loc) · 5.37 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# .bashrc
SYSTEM=$(uname -s 2> /dev/null)
case "$SYSTEM" in
CYGWIN*)
SYSTEM=cygwin
;;
MINGW*|MSYS*)
SYSTEM=msys
;;
Linux*)
SYSTEM=linux
case "$(uname -r)" in
*-Microsoft*)
SYSTEM_VARIANT=wsl
;;
esac
;;
FreeBSD)
SYSTEM=freebsd
;;
*)
SYSTEM=unknown
;;
esac
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f /etc/bash/bashrc ]; then
. /etc/bash/bashrc
fi
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
function pathadd()
{
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$PATH:$1"
fi
}
# run site-specific config if it exists
if [ -f ~/.bashrc.site ]; then
source ~/.bashrc.site
fi
pathadd "$HOME/bin"
pathadd "$HOME/src/go/bin"
pathadd "/sbin"
pathadd "/usr/sbin"
unset pathadd
[ -d "$HOME/src/go" ] && export GOPATH="$HOME/src/go"
unset TMP
unset TEMP
if [ -d /tmp ]; then
export TMP=/tmp
export TEMP=/tmp
else
mkdir -p ~/temp
export TMP=~/temp
export TEMP=~/temp
fi
umask 022
# enable core dumps
ulimit -c unlimited
# if not logging in interactively, stop here
#[ -z "$PS1" ] && return
[[ $- != *i* ]] && return
export EDITOR=vim
export PAGER=less
export LESS='-F -M -R -Q'
export MANOPT='--no-hyphenation --no-justification'
if [ -f ~/etc/git-completion.bash ]; then
. ~/etc/git-completion.bash
fi
# set XDG Base Directory vars if not provided by session
if [ -z "$XDG_DATA_HOME" ]; then
if [ "$SYSTEM" = "cygwin" -o "$SYSTEM" = "msys" ]; then
export XDG_DATA_HOME="$HOME/AppData/Roaming"
else
export XDG_DATA_HOME="$HOME/appdata"
fi
[ -d "$XDG_DATA_HOME" ] || mkdir "$XDG_DATA_HOME"
fi
if [ -z "$XDG_CONFIG_HOME" ]; then
export XDG_CONFIG_HOME="$HOME/.config"
[ -d "$XDG_CONFIG_HOME" ] || mkdir "$XDG_CONFIG_HOME"
fi
test -f "$XDG_CONFIG_HOME/user-dirs.dirs" && source "$XDG_CONFIG_HOME/user-dirs.dirs"
# -----------------------------
# put everything inside a function so variables don't unintentionally leak
# (use locals for things that shouldn't be exported)
function interactive ()
{
# normal foreground
local FG_BLACK="\[\033[30m\]"
local FG_RED="\[\033[31m\]"
local FG_GREEN="\[\033[32m\]"
local FG_YELLOW="\[\033[33m\]"
local FG_BLUE="\[\033[34m\]"
local FG_PURPLE="\[\033[35m\]"
local FG_CYAN="\[\033[36m\]"
local FG_WHITE="\[\033[37m\]"
# bold foreground
local FG_RED_B="\[\033[1;31m\]"
local FG_GREEN_B="\[\033[1;32m\]"
local FG_YELLOW_B="\[\033[1;33m\]"
local FG_BLUE_B="\[\033[1;34m\]"
local FG_PURPLE_B="\[\033[1;35m\]"
local FG_CYAN_B="\[\033[1;36m\]"
local FG_WHITE_B="\[\033[1;37m\]"
local BG_BLACK="\[\033[40m\]"
local BG_RED="\[\033[41m\]"
local COLOR_RESET="\[\033[0m\]"
# special case: mingw "dumb" terminal can still set title
# set TERM to mingw-dumb for now to indicate this and put it back later
if [ "$TERM" = "dumb" -a "$SYSTEM" = "msys" ]; then
TERM="mingw-dumb"
fi
# set window title in the prompt for terminals that support it
local PS1_TITLE
case "$TERM" in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|mingw-dumb*)
PS1_TITLE="\033]0;\\h:\\w\007"
;;
screen*)
PS1_TITLE="\033_\\h:\\w\033\""
;;
*)
PS1_TITLE=""
;;
esac
export PROMPT_COMMAND=""
# restore the original TERM if we temporarily changed it
if [ "$TERM" = "mingw-dumb" ]; then
TERM="dumb"
fi
PS1="\[${PS1_TITLE}\]\n${HOSTCOLOR}\\h${COLOR_RESET}${FG_WHITE}\`if [[ \$? -eq 0 ]]; then echo ':'; else echo '${BG_RED}!${COLOR_RESET}'; fi\`${FG_YELLOW_B}\\w\n${FG_GREEN_B}\\\$${COLOR_RESET} "
export PS1
unset HOSTCOLOR
# executing a dir name will cd to it
shopt -s autocd &> /dev/null
# fix small spelling errors in cd commands
shopt -s cdspell
# fix small spelling errors in directory names during completion
shopt -s dirspell &> /dev/null
# include filenames beginning with . in expansions
shopt -s dotglob
# do case-insensitive globbing
shopt -s nocaseglob
# append history from all terminals
shopt -s histappend
# check window size when bash regains control
shopt -s checkwinsize
# ignore duplicate history items
export HISTCONTROL=ignoredups
# use color when available
if ls --color=auto &> /dev/null; then
alias ls='ls --color=auto'
fi
alias grep='grep --color=auto'
alias hex='xxd -g 1 -u'
case "$SYSTEM" in
msys)
alias clear=clsb
;;
cygwin)
alias start=cygstart
;;
linux)
if [ "$SYSTEM_VARIANT" = 'wsl' ]; then
alias start='cmd.exe /c start'
else
alias start=xdg-open
fi
;;
esac
if [ ! -z "$DISPLAY" ]; then
xset b off &> /dev/null
fi
# turn off hover scrollbars
export GTK_OVERLAY_SCROLLING=0
# stop annoying messages from GTK3 apps about accessibility bus
# https://bugs.launchpad.net/ubuntu/+source/at-spi2-core/+bug/1193236
export NO_AT_BRIDGE=1
}
# call the function defined above
interactive
# remove it
unset interactive
# turn off stupid command not found handler some distros add
unset command_not_found_handle