-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
347 lines (293 loc) · 8.02 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# vim: set ft=sh :
# Set up the GPG Agent.
export GPG_TTY=$(tty)
#############################
# #
# Bash-specific stuff #
# #
#############################
# - histverify: Command history substitutions are put in the input line for
# verification, instead of being immediately run.
# - no_empty_cmd_completion: When completion is attempted on an empty line
# (press <Tab> on an empty line), bash won't look in $PATH for completing
# possible commands.
shopt -s histverify no_empty_cmd_completion
run_autoenv_on_init() {
if [ -z "$AUTOENV_RAN_ON_INIT" ]; then
cd /
cd - >/dev/null
AUTOENV_RAN_ON_INIT=1
fi
}
#################
# #
# autoenv #
# #
#################
# Find authorized and unauthorized autoenvs in these files.
[ -f ~/.autoenv_authorized ] || touch ~/.autoenv_authorized
[ -f ~/.autoenv_not_authorized ] || touch ~/.autoenv_not_authorized
# Enable autoenv leave too.
AUTOENV_ENABLE_LEAVE=1
# Rename autoenv files to less generic names.
AUTOENV_ENV_FILENAME=.autoenv.enter
AUTOENV_ENV_LEAVE_FILENAME=.autoenv.leave
source ~/.autoenv/activate.sh
################
# #
# Prompt #
# #
################
eval "$(starship init bash)"
###############################
# #
# Python-specific stuff #
# #
###############################
# Set up pyenv for each interactive shell.
eval "$(pyenv init -)"
################################
# #
# Homebrew's completions #
# #
################################
if type brew &>/dev/null; then
HOMEBREW_PREFIX="$(brew --prefix)"
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
done
fi
#################
# #
# Aliases #
# #
#################
# Search history.
alias h="history | grep"
#
# Search running processes.
alias p="ps aux | grep"
# Find out what is taking so much space on your drives!
alias diskspace="du -S | sort -n -r | more"
# Show me the size (sorted) of only the folders in this directory.
alias folders="find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn"
# Edit Bash configuration files.
alias erc='nvim -O ~/.bash_profile ~/.bashrc'
# Source Bash configuration files.
alias src='source ~/.bash_profile'
# Show path in readable format.
alias path='echo $PATH | tr : "\n"'
# Allows alias checking in watch commands.
alias watch='watch '
# Makes Neovim open multiple files in different buffers, all immediately
# visible, in the same tab.
alias v='\nvim -O'
alias vi='\nvim -O'
alias vim='\nvim -O'
alias nvim='\nvim -O'
# Ask before destructive actions.
alias cp='cp -i'
alias mv='mv -i'
# Docker aliases.
alias d='docker'
alias dc='docker compose'
alias docker-nuke-all-the-things='yes | docker system prune --volumes --all'
# Always ignore the .git directory.
alias tree='tree -I ''.git'''
#####################################
# #
# git aliases and completions #
# #
#####################################
alias g='git'
__git_complete g git
alias gnuke='g nuke'
alias gst='g st'
__git_complete gst git_status
alias gsh='g sh'
alias gshf='g shf'
alias gshh='g shh'
__git_complete gsh git_show
__git_complete gshf git_show
__git_complete gshh git_show
alias gl='g l'
__git_complete gl git_log
alias gb='g b'
alias gbr='g br'
alias gbn='g bn'
alias gbd='g bd'
__git_complete gb git_branch
__git_complete gbr git_branch
__git_complete gbn git_checkout
__git_complete gbd git_branch
alias gd='g d'
alias gdst='g dst'
alias gdca='g dca'
alias gdm='g dm'
__git_complete gd git_diff
__git_complete gdst git_diff
__git_complete gdca git_diff
__git_complete gdm git_diff
alias go='g o'
alias gom='g om'
alias gof='g of'
__git_complete go git_checkout
__git_complete gom git_checkout
__git_complete gof git_checkout
alias ga='g a'
alias gaa='g aa'
alias gapa='g apa'
__git_complete ga git_add
__git_complete gaa git_add
__git_complete gapa git_add
alias gc='g c'
alias gca='g ca'
alias gcm='g cm'
alias gcn='g cn'
alias gcam='g cam'
alias gcan='g can'
alias gcmn='g cmn'
alias gcamn='g camn'
alias gcw='g cw'
alias gucw='g ucw'
__git_complete gc git_commit
__git_complete gca git_commit
__git_complete gcm git_commit
__git_complete gcn git_commit
__git_complete gcam git_commit
__git_complete gcan git_commit
__git_complete gcmn git_commit
__git_complete gcamn git_commit
__git_complete gcw git_commit
__git_complete gucw git_reset
alias gcp='g cp'
__git_complete gcp git_cherry_pick
alias gr='g r'
alias gri='g ri'
alias grim='g rim'
__git_complete gr git_rebase
__git_complete gri git_rebase
__git_complete grim git_rebase
alias gp='g p'
alias gpf='g pf'
__git_complete gp git_push
__git_complete gpf git_push
alias gpu='g pu'
__git_complete gpu git_pull
###################
# #
# Functions #
# #
###################
gnh() { # git no hooks
echo "Disabling git hooks..."
mv "$(git root)/.git/hooks" "$(git root)/.git/hooks_dead"
eval $*
mv "$(git root)/.git/hooks_dead" "$(git root)/.git/hooks"
echo "Re-enabled git hooks."
}
# Find current default interface.
if [ "$JPMELOS_IS_MACOS" = "true" ]; then
default_if() {
route -n get default | grep 'interface:' | awk '{print $2}'
}
else
default_if() {
echo "Implement for Linux..."
}
fi
# Find the IP of the interface to the default gateway.
if [ "$JPMELOS_IS_MACOS" = "true" ]; then
default_if_ip() {
ifconfig "$(default_if)" | grep 'inet ' | awk '{print $2}'
}
else
default_if_ip() {
echo "Implement for Linux..."
}
fi
# Updates the system.
if [ "$JPMELOS_IS_MACOS" = "true" ]; then
update() {
brew update && brew upgrade
}
else
update() {
sudo apt-get --allow-releaseinfo-change update
sudo apt-get -y --allow-downgrades dist-upgrade
sudo apt-get -y autoremove
sudo apt-get -y clean
}
fi
# Extract stuff.
extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) rar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Determine actual size of a file in disk (considers entire blocks) or total
# size of a directory.
function fs() {
if du -b /dev/null >/dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* ./*
fi
}
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local addr="${1:-0.0.0.0}"
local port="${2:-8000}"
sleep 2 && open "http://$addr:$port/" &
python3 -m http.server "$port" -b "$addr"
}
# Compare original and gzipped file size.
function gz() {
local origsize=$(wc -c <"$1")
local gzipsize=$(gzip -c "$1" | wc -c)
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l)
printf "orig: %d bytes\n" "$origsize"
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio"
}
# Normalize `open` across Linux, macOS, and Windows.
# This is needed to make the `o` function (see below) cross-platform.
if [ ! $(uname -s) = 'Darwin' ]; then
if grep -q Microsoft /proc/version; then
# Ubuntu on Windows using the Linux subsystem
alias open='explorer.exe'
else
alias open='xdg-open'
fi
fi
# `o` with no arguments opens the current directory, otherwise opens the given
# location.
function o() {
if [ $# -eq 0 ]; then
open .
else
open "$@"
fi
}
function is_in_path() {
builtin type -P "$1" &>/dev/null
}