-
Notifications
You must be signed in to change notification settings - Fork 0
/
.everythingrc
executable file
·252 lines (204 loc) · 6.61 KB
/
.everythingrc
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
# Bash: .bash_profile (macOS default) -> .profile (Ubuntu default) -> .bashrc -> .everythingrc
# zsh: .zshrc (always executed) -> .everythingrc
: ${SHELL:=$(which "$(ps -o comm= $$ | sed 's/^-*//')")}
# https://docs.brew.sh/Shell-Completion
: ${HOMEBREW_PREFIX:=$(if type brew &> /dev/null; then brew --prefix; fi)}
if [[ ! -x "$(command -v brew)" && -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
##### Bash #####
if [[ -x "$(command -v brew)" ]]; then
# Load bash-completion
if [[ "$(basename "${SHELL}")" == "bash" ]]; then
__bash_completion() {
if [[ -f "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
# bash-completion@2
. "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
elif [[ -f "${HOMEBREW_PREFIX}/etc/bash_completion" ]]; then
# bash-completion@1
. "${HOMEBREW_PREFIX}/etc/bash_completion"
else
brew install bash-completion && __bash_completion
fi
# https://docs.brew.sh/Shell-Completion#configuring-completions-in-bash
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
done
}
__bash_completion
fi
# Load zsh/site-functions
if [[ "$(basename "${SHELL}")" == "zsh" ]]; then
__zsh_completion() {
# https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
# autoload -Uz compinit
# compinit
}
__zsh_completion
fi
fi
# Reload this file after change
reload() {
exec "${SHELL}"
}
##### Misc #####
__bashrc_misc() {
# `which` but better
# https://emmer.dev/blog/reliably-finding-files-in-path/
pinpoint() {
while read -r DIR; do
if [[ -f "${DIR}/$1" ]]; then
echo "${DIR}/$1"
return 0
fi
done <<< "$(echo "${PATH}" | tr ':' '\n')"
return 1
}
# Don't be a savage
if [[ -x "$(command -v nano)" ]]; then
EDITOR=$(pinpoint nano)
export EDITOR
fi
# Navigation helpers
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# Colorize various commands
# shellcheck disable=SC2139,SC2262
alias ls="command ls $(if ls --color &> /dev/null; then echo "--color"; else echo "-G"; fi)"
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
command -v tree > /dev/null && alias tree='tree -C'
# cat shortcuts
cathex() {
xxd -p "$@" | tr -d '\n' | awk '{print $1}'
}
# ls shortcuts
alias ll="ls -alF"
lsd() {
for DIR in "${@:-.}"/*; do
if [[ -d "${DIR}" ]]; then
echo "${DIR}"
fi
done
}
lsf() {
for FILE in "${@:-.}"/*; do
if [[ ! -d "${FILE}" ]]; then
echo "${FILE}"
fi
done
}
# Jokes
alias please="sudo"
alias yeet="rm -rf"
# Polyfills
if [[ ! -x "$(command -v beep)" ]]; then
alias beep="echo -ne '\007'"
fi
}
__bashrc_misc
##### 1Password #####
[[ -f "$HOME/.config/op/plugins.sh" ]] && builtin source "$HOME/.config/op/plugins.sh"
##### IDEs #####
__bashrc_ides() {
if [[ -d "/Applications/Visual Studio Code.app/Contents/Resources/app/bin" ]]; then
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
fi
if [[ -d "/Applications/VSCodium.app/Contents/Resources/app/bin" ]]; then
export PATH="$PATH:/Applications/VSCodium.app/Contents/Resources/app/bin"
alias code=codium
fi
}
__bashrc_ides
##### Golang #####
__bashrc_golang() {
# Set path environment variables
if [[ -x "$(command -v go)" ]]; then
if [[ ! -d "${GOROOT}" ]]; then
GOROOT=$(realpath "$(which go)" | sed 's/\/bin\/go$//')
export GOROOT
fi
GOPATH=$(go env GOPATH)
export GOPATH
if [[ ! -d "${GOPATH}" ]]; then
mkdir -p "${GOPATH}"
mkdir "${GOPATH}/bin"
mkdir "${GOPATH}/src"
fi
PATH="$PATH:$(go env GOPATH)/bin"
export PATH
fi
}
__bashrc_golang
##### Java #####
__bashrc_java() {
if [[ "${JAVA_HOME:-}" == "" && -x /usr/libexec/java_home ]]; then
export JAVA_HOME=$(/usr/libexec/java_home 2> /dev/null)
fi
if [[ "${JAVA_HOME:-}" == "" ]]; then
while read -r DIR; do
export JAVA_HOME="${DIR}"
done <<< "$((find /Library/Java/JavaVirtualMachines/*/Contents -type d -name Home) 2> /dev/null | sort --version-sort)"
fi
jversion() {
java --version | head -1 | sed 's/"//g' | sed -E 's/(.* )?([0-9]+\.[0-9]+\.[0-9]+[^ ]+).*/\2/'
}
}
__bashrc_java
##### MySQL #####
__bashrc_mysql() {
# Set path environment variables
if [[ -x "$(command -v brew)" ]]; then
while read -r DIR; do
if [[ -d "${DIR}/bin" ]]; then
export PATH="${DIR}/bin:${PATH}"
fi
done <<< "$(find "${HOMEBREW_PREFIX}/opt" -maxdepth 1 -name "mysql-client*")"
fi
}
__bashrc_mysql
##### Python #####
__bashrc_python() {
while read -r DIR; do
export PATH="${DIR}:${PATH}"
done <<< "$(find ~/Library/Python -type d -name bin 2> /dev/null)"
if [[ -d ~/grpc_tools ]]; then
export PATH=~/grpc_tools:$PATH
fi
if [[ -d ~/grpc_tools/grpc/bins/opt ]]; then
export PATH=~/grpc_tools/grpc/bins/opt:$PATH
fi
}
__bashrc_python
##### Ruby #####
__bashrc_ruby() {
# Lazy load chruby
if [[ -d "${HOMEBREW_PREFIX}/opt/chruby/share/chruby" ]]; then
chruby() {
unset -f "$0"
source "${HOMEBREW_PREFIX}/opt/chruby/share/chruby/chruby.sh"
source "${HOMEBREW_PREFIX}/opt/chruby/share/chruby/auto.sh"
$0 "$@"
}
fi
# Auto-load the latest Ruby version
if [[ -x "$(command -v chruby)" && -d ~/.rubies ]]; then
chruby "$(ls -1 ~/.rubies/ | sort | tail -1)"
fi
}
__bashrc_ruby
##### Everything Else #####
while read -r FILE; do
# shellcheck disable=SC1090
source "${FILE}"
done <<< "$(find ~ -maxdepth 1 -follow -type f -name ".*.bash" | sort --version-sort)"
if [[ "$(basename "${SHELL}")" == "zsh" ]]; then
while read -r FILE; do
# shellcheck disable=SC1090
source "${FILE}"
done <<< "$(find ~ -maxdepth 1 -follow -type f -name ".*.zsh" | sort --version-sort)"
fi