-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.dotrc
319 lines (264 loc) · 7.48 KB
/
.dotrc
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
#!/usr/bin/env bash
debug_out "Processing main dot configuration"
export PAGER='less -R'
export LESS='SX'
export HISTCONTROL=ignorespace:ignoredups
shopt -s histappend
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
# 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"
alias vim='nvim -O'
raw_vim_command='nvim'
alias vi='nvim'
alias evim='$EDITOR ~/.config/nvim/init.lua'
alias eplug='$EDITOR ~/.config/nvim/lua/plugins/all.lua'
alias ekeys='$EDITOR ~/.config/nvim/lua/config/keymap.lua'
export EDITOR=$raw_vim_command
export VISUAL=$raw_vim_command
alias eack='$EDITOR $DOT_HOME/.ackrc'
alias egit='$EDITOR $DOT_HOME/.gitconfig'
alias ebash="$EDITOR ~/.bashrc"
alias sbash='source ~/.bashrc'
# 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 idot='install_dot'
alias cdot='cd $DOT_HOME'
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 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'
if [[ $(uname) == "Darwin" ]]
then
alias ls='gls --color=tty'
alias ln='gln'
alias cp='gcp'
alias touch='gtouch'
alias ps='pstree -wg3 | less'
else
alias ls='ls --color=tty'
fi
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 tfm='terraform'
alias dc='docker compose'
alias fd='fdfind'
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 $@
}
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 "Detecting which ack"
which ack > /dev/null 2>&1
if (( $? ))
then
alias ack='ack-grep'
fi
# Start agent if it is not already started
if [[ -n "$SSH_AGENT_PID" ]]
then
debug_out "Agent already initialized. Skipping..."
else
debug_out "Initialising new SSH agent..."
eval "$(ssh-agent)"
fi
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"
dusktreader_ed25519_key="dusktreader.ed25519.secret"
dusktreader_ed25519_path="$HOME/.ssh/$dusktreader_ed25519_key"
if [[ -e $dusktreader_ed25519_path ]]
then
if [[ -z "$(ssh-add -l | grep $dusktreader_ed25519_key)" ]]
then
debug_out "$dusktreader_ed25519_key key not found in active ssh identities not found. Setting it up:"
ssh-add $dusktreader_ed25519_path
else
debug_out "$dusktreader_ed25519_key already added. Skipping..."
fi
else
debug_out "Didn't find any ssh key to add"
fi
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)
}
pyclean () {
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
}
install_dot() {
rm -rf .wheels/dot*
python -m pip install wheel
python -m pip wheel -w .wheels .
python -m pip install -U .wheels/dot*
}
pip_install_save() {
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./etc/setuptools/requirements.txt'
fi
pip install $package_name && pip freeze | grep -i "^$package_name==" >> $requirements_file
}
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
eval "$(oh-my-posh init bash --config ~/.config/oh-my-posh/dusktreader.omp.yaml)"