-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.dotrc
More file actions
355 lines (292 loc) · 8.11 KB
/
.dotrc
File metadata and controls
355 lines (292 loc) · 8.11 KB
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
348
349
350
351
352
353
354
355
#!/usr/bin/env bash
debug_out "Processing main dot configuration"
export PAGER='less'
export LESS='RSX'
export HISTCONTROL=ignorespace:ignoredups
if [[ "$OSTYPE" == "darwin"* ]]
then
setopt share_history
setopt noautomenu
else
shopt -s histappend
fi
# Not sure what this does any more, but I don't think I need it
# export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
export XAUTHORITY=$HOME/.Xauthority
HISTSIZE=1000000
HISTFILESIZE=1000000
export GIT_PS1_SHOWDIRTYSTATE=1
export DIFF_COLOR_DO_HORIZONTAL=1
export DIFF_COLOR_MERGE_ONE_LINERS=1
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:~/bin:/Applications/Postgres.app/Contents/Versions/latest/bin
export PATH=$PATH:~/.local/bin
export GOENV_ROOT="$HOME/.goenv"
export PATH="$PATH:$GOENV_ROOT/bin"
export PATH=$PATH:~/.local/share/npm/bin
# Add yarn binaries to the path
export PATH="~/.yarn/bin/:$PATH"
# Add go binaries to the path
export PATH="/usr/local/go/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
# Add generic binaries to the path
export PATH="~/bin:$PATH"
ppath () {
echo "Current directories in path:"
echo "----------------------------"
echo "$PATH" | tr ":" "\n"
}
if [[ -n "$WSL_DISTRO_NAME" ]]
then
export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"
fi
# Stupid hack so that neovim installed from snap can use node installed from snap
export PATH="/snap/node/current/bin:$PATH"
alias vim='nvim -O'
raw_vim_command='nvim'
alias vi='nvim'
alias evim='$EDITOR $DOT_HOME/.config/nvim/init.lua'
alias fvim='nvim $(fzf --preview="cat {}")'
alias cplug='cd $DOT_HOME/.config/nvim/lua/plugins/'
alias eplug='$EDITOR $DOT_HOME/.config/nvim/lua/plugins/'
alias ekeys='$EDITOR $DOT_HOME/.config/nvim/lua/user/keymap.lua'
export EDITOR=$raw_vim_command
export VISUAL=$raw_vim_command
alias eack='$EDITOR $DOT_HOME/.ackrc'
alias egit='$EDITOR $DOT_HOME/.gitconfig'
if [[ "$OSTYPE" == "darwin"* ]]
then
rc="$HOME/.zshrc"
else
rc="$HOME/.bashrc"
fi
alias ebash="$EDITOR $rc"
alias sbash="source $rc"
# TODO: this should have a configurable dot location based on dot-configure root
alias edot="$EDITOR $DOT_HOME/.dotrc"
alias sdot='source $DOT_HOME/.dotrc'
alias cdot='cd $DOT_HOME'
alias pdot='pushd $DOT_HOME'
alias cnotes='cd $HOME/git-repos/personal/notes'
alias pnotes='pushd $HOME/git-repos/personal/notes'
alias enotes='$EDITOR $HOME/git-repos/personal/notes'
alias cdwork='cd $HOME/git-repos/omnivector'
alias cdmine='cd $HOME/git-repos/personal'
alias ecoc="$EDITOR $DOT_HOME/.config/nvim/coc-settings.json"
alias einstall="$EDITOR $DOT_HOME/install.sh"
alias rinstall="$DOT_HOME/install.sh"
alias elualine="$EDITOR $DOT_HOME/.config/nvim/lualine.lua"
alias eposh="$EDITOR $DOT_HOME/.config/oh-my-posh/dusktreader.omp.yaml"
alias egrep='egrep --color=auto'
alias grep='egrep --color=auto'
alias fvim='fzf --print0 | xargs -0 -o nvim'
alias cojira='checkout-branch-by-pattern'
alias cb='current-branch'
alias sl='ls'
alias ls='ls --color=tty'
alias cd='fancy_cd'
alias less='less -RNJMw -z-4'
alias activate='source $(ls | grep env)/bin/activate'
alias gti='git'
alias nofail='py.test test* --maxfail=1 -m "not slow"'
alias nofailall='py.test test --maxfail=1'
alias terraform="terraform1.13"
alias tfm='terraform'
alias dc='docker compose'
if [[ "$OSTYPE" != "darwin"* ]]
then
alias fd='fdfind'
fi
alias k='kubectl'
alias mk='microk8s.kubectl'
alias wjst='watch -n 1 -c juju status --color'
dcup () {
services=$@
docker compose up --detach $@ && docker compose logs --follow --tail=30 $@
}
dcw () {
services=$@
docker compose up --build --watch $@
}
function wisdom {
curl -s -X GET -H "Content-Type: application/json" https://zenquotes.io/api/random | jq -r '" " as $space | .[0] | .q + "\n\n\($space * ((.q |length)-(.a |length) - 2))--" + .a' | cowsay -nsf $(cowsay -l | tail -n +2 | tr ' ' '\n' | shuf -n1) | lolcat
}
export PATH="$HOME/.nodenv/bin:$PATH"
debug_out "Initializing nodenv"
which nodenv > /dev/null 2>&1
if (( $? ))
then
debug_out "Did not detect nodenv. Skipping"
else
eval "$(nodenv init -)"
debug_out "Finished initializing nodenv"
fi
debug_out "Initializing jenv"
which jenv > /dev/null 2>&1
if (( $? ))
then
debug_out "Did not detect jenv. Skipping"
else
eval "$(jenv init -)"
debug_out "Finished initializing jenv"
fi
debug_out "Detecting which ack"
which ack > /dev/null 2>&1
if (( $? ))
then
alias ack='ack-grep'
fi
# Start agent if it is not already started
bind_ssh_agent
poetry_env_path=$HOME/.poetry/env
if [[ -e $poetry_env_path ]]
then
source $poetry_env_path
debug_out "Initialized poetry"
fi
debug_out "Adding ssh keys to agent"
keys=(
"dusktreader.ed25519"
"tucker.beck.ed25519"
)
for key in "${keys[@]}";
do
key_path="$HOME/.ssh/$key"
if [[ -e $key_path ]]
then
if [[ -z "$(ssh-add -l | grep $key)" ]]
then
debug_out "$key key not found in active ssh identities not found. Setting it up:"
ssh-add $key_path
else
debug_out "$key already added. Skipping..."
fi
else
debug_out "Couldn't find ssh key named $key to add"
fi
done
nuke () {
branch_name=$1
local_name=$(echo $1 | sed s#origin/##)
remote_name=origin/$local_name
echo "Nuking $1 locally and on origin"
echo "Latest commits:"
echo "==============="
echo "local"
echo "-----"
git --no-pager log -n 1 --pretty=format:"%h - %an (%ar): %s" $local_name
echo
echo "remote"
echo "-----"
git --no-pager log -n 1 --pretty=format:"%h - %an (%ar): %s" $remote_name
echo
echo "....."
read -p "Press ENTER to continue"
git branch -D $1
git push origin --delete $1
}
ematch () {
pattern=$1
path=$2
command vim $(ack -l $pattern $path)
}
envo() {
env_file=$1
verbose=$2
if [[ -z $env_file ]]
then
echo "You must supply an environment file as the first arg"
return 1
fi
if [[ ! -e $env_file ]]
then
echo "The supplied env file doesn't exist"
return 1
fi
if [[ -n $verbose ]]
then
echo "Setting environment variables..."
fi
while IFS='' read -r LINE || [ -n "${LINE}" ]; do
if [[ -n $verbose ]]
then
echo "${LINE}"
fi
export $LINE
done < $1
# export $(grep -v '^#' $env_file | xargs -0)
}
count_files_in_subdirs() {
target_dir=$1
if [[ -z $target_dir ]]
then
echo "Please supply a target directory" >&2
return 1
fi
debug_out "Counting files in subdirectories of $(readlink -f $target_dir)"
sort_arg=$2
if [[ -z $sort_arg ]]
then
sort_arg="-k2rn"
fi
timestamp=$(date '+%Y%m%d_%H%M%S')
filename="/tmp/$timestamp-counts.txt"
rm -f $filename
for subdir in $(find $target_dir -maxdepth 1 -type d ! -path . )
do
echo "$subdir: $(find $subdir -type f | wc -l)" >> $filename
done
cat $filename | sort $sort_arg
}
smart_ls() {
target=$1
simple_list=$(command ls -1 $target) || return
count=$(echo $simple_list | wc -w)
if (( $count == 0 ))
then
echo "Directory is empty"
elif (( $count <= 10 ))
then
ls -l --color=tty $target
elif (( $count <= 100 ))
then
ls --color=tty $target
else
echo "Directory contains $count files"
fi
}
fancy_cd() {
newdir=$1
builtin cd $newdir || return
smart_ls .
}
abs_path() {
path=$1
if [[ -z $path ]]
then
pwd
return
fi
python -c "import os; print(os.path.realpath('$path'))"
}
debug_out "Overriding virtualenv PS1 settings"
export VIRTUAL_ENV_DISABLE_PROMPT=1
function venv_info {
if [[ -n "$VIRTUAL_ENV" ]]
then
echo "/venv:${VIRTUAL_ENV##*/}/ "
else
echo ""
fi
}
export VENV_INFO="\$(venv_info)"
# Load my oh-my-posh theme
if [[ "$OSTYPE" == "darwin"* ]]
then
eval "$(oh-my-posh init zsh --config ~/.config/oh-my-posh/dusktreader.omp.yaml)"
else
eval "$(oh-my-posh init bash --config ~/.config/oh-my-posh/dusktreader.omp.yaml)"
fi
eval "$(goenv init -)"