-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
254 lines (216 loc) · 6.28 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Bash environment
# exit if shell is non-interactive
if [[ $- != *i* ]]; then
return
fi
# bash version
bash_version=${BASH_VERSION%%.*}
# disable C-s (vim)
stty -ixon
# disable C-q (screen, tmux)
stty -ixoff
# checks the window size after each command
shopt -s checkwinsize
# os system name
os_name=$(uname -s)
# architecture type & os system version
if [[ $os_name == "Darwin" ]]; then
arch=$(uname -m)
os_version=$(uname -v)
fi
# ls, grep output color
ls_color=0
grep_color=1
# see CLICCOLOR for FreeBSD
if [[ $ls_color == 1 ]]; then
alias ls="ls --color=auto -F"
else
alias ls="ls -F"
fi
# color for (grep, fgrep, egrep)
if [[ $grep_color == 1 ]]; then
alias grep="grep --color=auto"
alias fgrep="grep -F --color=auto"
alias egrep="grep -E --color=auto"
export GREP_COLORS="mt=31" # red
fi
# interactive confirm
alias cp="cp -i"
alias mv="mv -i"
alias rm="rm -i"
# vim
if [[ $VIMRUNTIME =~ "MacVim" ]]; then
alias vim="echo 'Error: do not use an instance of MacVim inside MacVim'"
alias gvim="vim"
alias view='vim'
alias rview='vim'
# else
# looks like some vim version does not work with this
# alias vim="vim -u ~/.vim/vimrc"
# alias gvim="gvim -u ~/.vim/vimrc"
# alias view="view -u ~/.vim/vimrc"
# alias rview="rview -u ~/.vim/vimrc"
fi
# emacs (without gui)
alias emacs="emacs -nw"
# set a reasonable default umask
# -rw-r--r-- for regular files
# drwxr-xr-x for directories
umask 22
# disable bash version warning
if [[ $os_name == "Darwin" ]] && ((bash_version <= 3)); then
export BASH_SILENCE_DEPRECATION_WARNING=1
fi
# PS1 prompt
if [[ $USER == "root" ]]; then
export PS1="\w\e[0;31m\]#\[\e[0m "
else
# macOS arm64 with rosetta x86_64
rosseta_icon=$( [[ $os_name == "Darwin" ]] && [[ $arch == "x86_64" ]] && [[ $os_version =~ "RELEASE_ARM64" ]] && echo "${arch}:" || echo "")
export PS1="${rosseta_icon}\w\$ "
fi
# default
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
# local
local_path="/usr/local/sbin /usr/local/bin /usr/pkg/sbin /usr/pkg/bin /opt/sbin /opt/bin"
for path in $local_path; do
[[ -d $path ]] && PATH="${PATH}:${path}"
done
# home
[[ -d ${HOME}/opt/bin ]] && PATH="${HOME}/opt/bin:${PATH}"
[[ -d ${HOME}/bin ]] && PATH="${HOME}/bin:${PATH}"
# pkgsrc
[[ -d ${HOME}/opt/pkg/sbin ]] && PATH="${PATH}:${HOME}/opt/pkg/sbin"
[[ -d ${HOME}/opt/pkg/bin ]] && PATH="${PATH}:${HOME}/opt/pkg/bin"
# mac ports
[[ -d /opt/local/sbin ]] && PATH="${PATH}:/opt/local/sbin"
[[ -d /opt/local/bin ]] && PATH="${PATH}:/opt/local/bin"
# plan9
PLAN9="${HOME}/opt/plan9" && [[ -d $PLAN9 ]] && export PLAN9
[[ -d ${PLAN9}/bin ]] && PATH="${PATH}:${PLAN9}/bin"
# go
GOROOT="${HOME}/opt/go" && [[ -d $GOROOT ]] && export GOROOT
GOPATH="${HOME}/go" && [[ -d $GOPATH ]] && export GOPATH
GOBIN="${GOPATH}/bin" && [[ -d $GOBIN ]] && export GOBIN
[[ -d ${GOROOT}/bin ]] && PATH="${PATH}:${GOROOT}/bin"
[[ -d ${GOPATH}/bin ]] && PATH="${PATH}:${GOPATH}/bin"
# aws
AWS="${HOME}/opt/aws"
[[ -d ${AWS}/bin ]] && PATH="${PATH}:${AWS}/bin"
# set
export PATH
# MANPATH
if [[ $os_name == "Linux" ]]; then
MANPATH=$(manpath -g)
elif [[ $os_name == "Darwin" ]]; then
MANPATH=$(manpath)
fi
if [[ -n $MANPATH ]]; then
[[ -d /opt/local/share/man ]] && MANPATH=/opt/local/share/man:${MANPATH}
[[ -d ${HOME}/opt/pkg/man ]] && MANPATH=${HOME}/opt/pkg/man:${MANPATH}
[[ -d ${HOME}/opt/man ]] && MANPATH=${HOME}/opt/man:${MANPATH}
export MANPATH
fi
# prompt command title (dwm, xmonad, wmii, etc..)
case $TERM in
xterm|xterm-256color|screen|screen-256color|screen-256color-bce|tmux|tmux-256color|alacritty)
# remote ssh user@hostname
if [[ -n $REMOTEHOST ]]; then
export PROMPT_COMMAND='printf "\033]0;${USER}@${HOSTNAME}:${PWD}\007"'
else
# automatic screen window titles
if [[ -n "$STY" ]]; then
export PROMPT_COMMAND='printf "\033k\033\134\033]0;${PWD/#${HOME}/\~}\007"'
else
export PROMPT_COMMAND='printf "\033]0;${PWD/#${HOME}/\~}\007"'
fi
fi
;;
esac
# default editor
if hash vim 2>/dev/null; then
export EDITOR="vim"
export VISUAL="vim"
elif hash vi 2>/dev/null; then
export EDITOR="vi"
export VISUAL="vi"
fi
# default pager
if hash less 2>/dev/null; then
export PAGER="less"
export LESSCHARSET="utf-8"
export LESS="-R -M -X"
elif hash more 2>/dev/null; then
export PAGER="more"
fi
# manpages with color support
if [[ $PAGER == "most" ]]; then
export MANCOLOR
fi
# default browser
if hash firefox 2>/dev/null; then
export BROWSER="firefox"
elif hash ise 2>/dev/null; then
export BROWSER="ise"
elif hash lynx 2>/dev/null; then
export BROWSER="lynx"
elif hash links 2>/dev/null; then
export BROWSER="links"
fi
# fzf
if hash fd 2>/dev/null; then
export FZF_DEFAULT_COMMAND="fd --type f --follow --no-ignore --strip-cwd-prefix --color=never"
elif hash rg 2>/dev/null; then
export FZF_DEFAULT_COMMAND="rg --files --no-ignore --follow --color=never"
fi
# locales
case $os_name in
Linux|Darwin)
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
;;
FreeBSD)
export LANG="en_US.UTF-8"
export MM_CHARSET="en_US.UTF-8"
;;
NetBSD)
export LANG="en_US.UTF-8"
export LC_TYPE="en_US.UTF-8"
export LC_ALL=""
;;
esac
# bash completion
if [[ $os_name == "Linux" ]]; then
if [[ -f /usr/share/bash-completion/bash_completion ]]; then
. /usr/share/bash-completion/bash_completion
fi
elif [[ $os_name == "Darwin" ]]; then
if ((bash_version >= 5)); then
if [[ -f ${HOME}/opt/pkg/bash-completion/bash_completion ]]; then
. ${HOME}/opt/pkg/bash-completion/bash_completion
elif [[ -f /opt/local/etc/profile.d/bash_completion.sh ]]; then
. /opt/local/etc/profile.d/bash_completion.sh
fi
fi
fi
# completion aws cli
if [[ -f ${AWS}/bin/aws_completer ]]; then
complete -C "${AWS}/bin/aws_completer" aws
elif hash aws_completer 2>/dev/null; then
complete -C "$(command -v aws_completer)" aws
fi
# completion kubernetes cli (kubectl)
if [[ -f ${HOME}/.bash_kubernetes ]]; then
. ${HOME}/.bash_kubernetes
fi
# completion extra tools
if [[ $os_name == "Darwin" ]]; then
complete -A command caffeinate
fi
complete -A directory -A file tig
# enable xterm 256 colors (vim, tmux, tig, etc..)
if [[ -z $TMUX ]] && [[ -f /usr/share/terminfo/x/xterm-256color || -f /lib/terminfo/x/xterm-256color || $os_name == "Darwin" ]]; then
if [[ $TERM == "xterm" ]]; then
export TERM=xterm-256color
fi
fi