-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_bashrc.tmpl
301 lines (249 loc) · 10.2 KB
/
dot_bashrc.tmpl
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# SPDX-FileCopyrightText: Chris Wilson <[email protected]>
#
# SPDX-License-Identifier: MIT
# The Bash shell personal interactive initialization script file.
# (only read by a Bash shell that's both interactive and non-login)
# https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
# shellcheck shell=bash
# ------------------------------------------------------------------------------
# Debug info
# ------------------------------------------------------------------------------
export BASHRC_WAS_SOURCED=1
# ------------------------------------------------------------------------------
# Source shell functions
# ------------------------------------------------------------------------------
if [[ -r "${HOME}/.bash_functions" ]]; then
# shellcheck source=dot_bash_functions
. "${HOME}/.bash_functions"
fi
# ------------------------------------------------------------------------------
# Silence /bin/bash deprecation warning on macOS
# ------------------------------------------------------------------------------
export BASH_SILENCE_DEPRECATION_WARNING=1
# ------------------------------------------------------------------------------
# Environment Configuration
# ------------------------------------------------------------------------------
# enable en_US locale w/ utf-8 encodings if not already configured
: "${LANG:="en_US.UTF-8"}"
: "${LANGUAGE:="en"}"
: "${LC_CTYPE:="en_US.UTF-8"}"
: "${LC_ALL:="en_US.UTF-8"}"
export LANG LANGUAGE LC_CTYPE LC_ALL
# filename completion ignores
export FIGNORE="~:CVS:#:.pyc:.bak"
# history options
export HISTCONTROL=ignoreboth
export HISTFILESIZE=10000
export HISTSIZE=10000
# append to the history file, don't overwrite it
shopt -s histappend
# immediately add commands to history (don't wait for the end of each session)
# export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
# ------------------------------------------------------------------------------
# Editor
# ------------------------------------------------------------------------------
# TextMate
# export EDITOR='/usr/local/bin/mate -w'
# Sublime
# export EDITOR='subl -w'
# Atom
# export EDITOR='atom --wait'
# Visual Studio Code
export EDITOR='code --wait'
# ------------------------------------------------------------------------------
# Colors
# ------------------------------------------------------------------------------
# From http://en.wikipedia.org/wiki/ANSI_escape_code
# Escape sequences start with the character ESC (ASCII decimal 27/hex 0x1B/octal
# 033). For two character sequences, the second character is in the range ASCII
# 64 to 95 (@ to _). However, most of the sequences are more than two
# characters, and start with the characters ESC and [ (left bracket). This
# sequence is called CSI for Control Sequence Introducer (or Control Sequence
# Initiator). The final character of these sequences is in the range ASCII 64 to
# 126 (@ to ~).
# ANSI Escape
export ANSI_ESC="\033"
# ANSI Control Sequence Introducer
export ANSI_CSI="${ANSI_ESC}["
# SGR (Select Graphic Rendition) parameters
export SGR_RESET="0"
export SGR_BOLD="1"
export SGR_FAINT="2"
export SGR_ITALIC="3"
export SGR_UNDERLINE="4"
export SGR_BLINK_SLOW="5"
export SGR_BLINK_RAPID="6"
export SGR_IMAGE_NEGATIVE="7"
export SGR_CONCEAL="8"
export SGR_CROSSED_OUT="9"
export SGR_FG_BLACK="30"
export SGR_FG_RED="31"
export SGR_FG_GREEN="32"
export SGR_FG_YELLOW="33"
export SGR_FG_BLUE="34"
export SGR_FG_MAGENTA="35"
export SGR_FG_CYAN="36"
export SGR_FG_WHITE="37"
export SGR_BG_BLACK="40"
export SGR_BG_RED="41"
export SGR_BG_GREEN="42"
export SGR_BG_YELLOW="43"
export SGR_BG_BLUE="44"
export SGR_BG_MAGENTA="45"
export SGR_BG_CYAN="46"
export SGR_BG_WHITE="47"
# Reset Color
export COLOR_RESET="${ANSI_CSI}${SGR_RESET}m"
# Normal Colors
export COLOR_BLACK="${ANSI_CSI}${SGR_FG_BLACK}m"
export COLOR_RED="${ANSI_CSI}${SGR_FG_RED}m"
export COLOR_GREEN="${ANSI_CSI}${SGR_FG_GREEN}m"
export COLOR_YELLOW="${ANSI_CSI}${SGR_FG_YELLOW}m"
export COLOR_BLUE="${ANSI_CSI}${SGR_FG_BLUE}m"
export COLOR_MAGENTA="${ANSI_CSI}${SGR_FG_MAGENTA}m"
export COLOR_CYAN="${ANSI_CSI}${SGR_FG_CYAN}m"
export COLOR_WHITE="${ANSI_CSI}${SGR_FG_WHITE}m"
# Bold Colors
export COLOR_BOLD_BLACK="${ANSI_CSI}${SGR_BOLD};${SGR_FG_BLACK}m"
export COLOR_BOLD_RED="${ANSI_CSI}${SGR_BOLD};${SGR_FG_RED}m"
export COLOR_BOLD_GREEN="${ANSI_CSI}${SGR_BOLD};${SGR_FG_GREEN}m"
export COLOR_BOLD_YELLOW="${ANSI_CSI}${SGR_BOLD};${SGR_FG_YELLOW}m"
export COLOR_BOLD_BLUE="${ANSI_CSI}${SGR_BOLD};${SGR_FG_BLUE}m"
export COLOR_BOLD_MAGENTA="${ANSI_CSI}${SGR_BOLD};${SGR_FG_MAGENTA}m"
export COLOR_BOLD_CYAN="${ANSI_CSI}${SGR_BOLD};${SGR_FG_CYAN}m"
export COLOR_BOLD_WHITE="${ANSI_CSI}${SGR_BOLD};${SGR_FG_WHITE}m"
# http://unix.stackexchange.com/questions/2897/clicolor-and-ls-colors-in-bash
export CLICOLOR=yes
export GREP_OPTIONS='--color=auto'
export LS_OPTIONS='--color=auto'
# http://www.geekology.co.za/blog/2009/04/enabling-bash-terminal-directory-file-color-highlighting-mac-os-x/
# export LSCOLORS=ExFxCxDxBxegedabagacad
# ------------------------------------------------------------------------------
# Aliases
# ------------------------------------------------------------------------------
# disk usage with human sizes and minimal depth
alias du1='du -h -d 1'
alias fn='find . -name'
alias hi='history | tail -20'
alias ls="eza --group --icons"
alias la="ls -a" # list all, includes dot files
alias ll="ls -l" # long list, excludes dot files
alias lla="ls -la" # long list all, includes dot files
alias grep="rg"
{{- if eq .chezmoi.os "linux" }}
{{- if eq .chezmoi.osRelease.id "ubuntu" }}
alias cat="batcat"
{{ end }}
{{ else }}
alias cat="bat"
{{ end }}
alias ppath="echo \$PATH | tr ':' '\n'"
# https://support.typora.io/Use-Typora-From-Shell-or-cmd/
alias typora="open -a typora"
# https://jira.atlassian.com/browse/SRCTREE-7794
# https://jira.atlassian.com/browse/SRCTREE-3172
# alias stree='/Applications/SourceTree.app/Contents/Resources/stree'
# alias for x86_64 homebrew
alias brew-x86_64="arch -x86_64 /usr/local/homebrew/bin/brew"
# ------------------------------------------------------------------------------
# Homebrew Bash Completion
# ------------------------------------------------------------------------------
if [[ -n "${HOMEBREW_PREFIX}" ]] && [[ -d "${HOMEBREW_PREFIX}" ]]; then
# bash version check code copied from `starship init bash`
major="${BASH_VERSINFO[0]}"
minor="${BASH_VERSINFO[1]}"
if ((major > 4)) || { ((major == 4)) && ((minor >= 2)); }; then
# Make sure you add this after any PATH manipulation as otherwise the
# bash-completion will not work correctly.
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]
then
# shellcheck source=/dev/null
. "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*
do
# shellcheck source=/dev/null
[[ -r "${COMPLETION}" ]] && . "${COMPLETION}"
done
fi
else
echo
echo "WARNING: Bash completion is unavailable."
echo
echo "Homebrew bash-completion@2 requires bash >= 4.2"
echo
echo "\$BASH_VERSION=${BASH_VERSION}"
echo
fi
fi
# ------------------------------------------------------------------------------
# 1Password CLI
# ------------------------------------------------------------------------------
if executable_exists op; then
op_completions=$(op completion bash)
eval "${op_completions}"
fi
# ------------------------------------------------------------------------------
# rbenv
# ------------------------------------------------------------------------------
if [[ -n "${RBENV_ROOT}" ]] && [[ -d "${RBENV_ROOT}" ]]; then
# Don't use `rbenv init -` directly because it sets the PATH. Instead,
# remove any lines that set the PATH and then eval.
rbenv_init=$(rbenv init -)
rbenv_init_no_path=$(sed '/export PATH/d' <<< "${rbenv_init}")
eval "${rbenv_init_no_path}"
fi
# ------------------------------------------------------------------------------
# uv Bash completion
# ------------------------------------------------------------------------------
if executable_exists uv; then
uv_completion_bash=$(uv generate-shell-completion bash)
eval "${uv_completion_bash}"
fi
# ------------------------------------------------------------------------------
# pip Bash completion
# ------------------------------------------------------------------------------
# https://pip.pypa.io/en/stable/user_guide/#command-completion
if executable_exists pip; then
pip_completion_bash=$(pip completion --bash)
eval "${pip_completion_bash}"
fi
# ------------------------------------------------------------------------------
# rustup Bash completion
# ------------------------------------------------------------------------------
# https://rust-lang.github.io/rustup/installation/index.html
if executable_exists rustup; then
rustup_completions_bash=$(rustup completions bash)
eval "${rustup_completions_bash}"
fi
{{- if eq .chezmoi.os "linux" }}
# ------------------------------------------------------------------------------
# Initialize keychain
# ------------------------------------------------------------------------------
# if executable_exists keychain; then
# keychain_init_bash=$(keychain --eval id_rsa)
# eval "${keychain_init_bash}"
# fi
{{- end }}
# ------------------------------------------------------------------------------
# Initialize Starship prompt
# ------------------------------------------------------------------------------
# https://starship.rs/guide/#%F0%9F%9A%80-installation
if executable_exists starship; then
starship_init_bash=$(starship init bash)
eval "${starship_init_bash}"
fi
# ------------------------------------------------------------------------------
# direnv
# ------------------------------------------------------------------------------
if executable_exists direnv; then
direnv_hook_bash=$(direnv hook bash)
eval "${direnv_hook_bash}"
fi
# ------------------------------------------------------------------------------
# fzf
# ------------------------------------------------------------------------------
if executable_exists fzf; then
fzf_bash=$(fzf --bash)
eval "${fzf_bash}"
fi