-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc-snowflake
464 lines (432 loc) · 14 KB
/
.bashrc-snowflake
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#!/usr/bin/env bash
######## TERMINAL CONFIG
#BEGIN better autocomplete for sudo
complete -cf sudo
#END better autocomplete for sudo
# BEGIN custom code to set prompt
export PS1="\h:\w\$ "
# End custom code to set prompt
# BEGIN suppress bash warning
export SHELL=/bin/bash
export BASH_SILENCE_DEPRECATION_WARNING=1
# End suppress bash warning
# BEGIN suppress dumb term warning
if [[ -n $INSIDE_EMACS ]]; then
export TERM=xterm
fi
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
######## USEFUL ALIASES
# BEGIN update bashrc
alias eb="emacs ~/.bashrc"
alias sb="source ~/.bashrc"
# END update bashrc
# better which
alias which=type
# end better which
# better mv
alias mv-mv=/bin/mv
function maybe-git-mv ()
{
local repo
repo=$(git rev-parse --show-toplevel 2> /dev/null)
if [[ -e "${repo}" ]]; then
echo "Using git mv -- if you want normal mv use mv-mv";
git mv "$@";
else
mv-mv "$@";
fi
}
alias mv=maybe-git-mv
#end better mv
# better rm
alias rm-rm=/bin/rm
function maybe-git-rm ()
{
local repo
repo=$(git rev-parse --show-toplevel 2> /dev/null)
if [[ -e "${repo}" ]]; then
echo "Using git rm -- if you want normal rm use rm-rm";
git rm "$@";
else
rm-rm "$@";
fi
}
alias rm=maybe-git-rm
#end better rm
# swap two files
function swap()
{
local TMPFILE=tmp.$$
mv "$1" $TMPFILE && mv "$2" "$1" && mv $TMPFILE "$2"
}
function swap-swap()
{
local TMPFILE=tmp.$$
mv-mv "$1" $TMPFILE && mv-mv "$2" "$1" && mv-mv $TMPFILE "$2"
}
alias sw=swap
alias sw-sw=swap-swap
# END swap two files
# From https://stackoverflow.com/questions/12198222/go-up-several-directories-in-linux
# cd up to n dirs
# usage: up 10 up dir
function up() {
case $1 in
*[!0-9]*) # if not a number
echo "going up to $1"
pushd $( pwd | sed -r "s|(.*/$1[^/]*/).*|\1|" ) # search dir_name in current path, if found - cd to it
;; # if not found - not cd
*)
if [[ -z $1 ]]; then
echo "going up"
else
echo "going up $1 times"
fi
pushd $(printf "%0.0s../" $(seq 1 $1)); # cd ../../../../ (N dirs)
;;
esac
}
alias '..'=up # can not name function 'cd..'
# Begin ls color setup
alias ls='ls -GpF'
alias ll='ls -lh'
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# End ls color setup
#BEGIN rb
alias rb="irb --simple-prompt"
#END rb
#BEGIN lsl
alias lsl='find . -ls -name "*~" -prune'
#END lsl
#BEGIN start minecraft server
alias mc-start='exec java -Xms1G -Xmx1G -jar server.jar nogui;'
#END start minecraft server
#BEGIN start google chrome
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
#END start google chrome
#BEGIN whoami aliases
alias whoami-test='nosetests -v ~/whoami/tests && whoami-lint'
alias whoami-lint='pycodestyle ~/whoami/whoami ~/whoami/tests ~/whoami/scripts --ignore=E501,W504'
alias whoami-run='python ~/whoami/scripts/run.py'
alias astro-test='astro && astro-lint && python -m nose2 -v'
alias ast=astro-test
alias astro-lint='pycodestyle ~/astroparse/astroparse ~/astroparse/tests --ignore=E501,W504'
elint () {
# whoami lint
lint_files=$(whoami-lint -q | paste -sd " " -)
if [ -n "$lint_files" ]; then
emacs "$@" "$lint_files"
else
echo "Nothing to lint in whoami! Yay :)"
fi
# astroparse lint
lint_files=$(astro-lint -q | paste -sd " " -)
if [ -n "$lint_files" ]; then
emacs "$@" "$lint_files"
else
echo "Nothing to lint in astroparse! Yay :)"
fi
}
autolint () {
# whoami lint
lint_files=$(whoami-lint -q | paste -sd " " -)
if [ -n "$lint_files" ]; then
autopep8 --in-place --ignore=E501,W504 "$@" "$lint_files"
else
echo "Nothing to lint in whoami! Yay :)"
fi
# astroparse lint
lint_files=$(astro-lint -q | paste -sd " " -)
if [ -n "$lint_files" ]; then
autopep8 --in-place --ignore=E501,W504 "$@" "$lint_files"
else
echo "Nothing to lint in astroparse! Yay :)"
fi
}
alias ai='astro; astroparse-interactive -vsop'
alias aib='astrob; astroparse-interactive -vsop'
alias ts='astro; astroparse-try-parsers'
alias tsb='astrob; astroparse-try-parsers'
alias rlwrap-ai='astro; rlwrap astroparse-interactive -vsop'
alias rlwrap-ts='astro; rlwrap astroparse-try-parsers'
function astro () {
cd ~/astroparse || return
workon astro
}
function astrob () {
# astro-backup
cd ~/astroparse2 || return
workon astrob
}
function astro3 () {
workon astro3 && rmvirtualenv astro && cpvirtualenv astro3 astro && astro
}
function astro2 () {
workon astro2 && rmvirtualenv astro && cpvirtualenv astro2 astro && astro
}
#END whoami aliases
#BEGIN fix muted audio macOSX
alias fix-audio="sudo killall coreaudiod"
#END fix muted audio maxOSX
########### GIT TOOLS
#BEGIN git auto-complete (https://apple.stackexchange.com/questions/55875/git-auto-complete-for-branches-at-the-command-line)
test -f ~/.git-completion.bash && . "$_"
#END git auto-complete
#BEGIN use emacs to open all affected files in a git diff
ediff () {
emacs "$(git diff --name-only $@ | paste -sd " " -)"
}
#END use emacs to open all affected files in a git diff
#BEGIN analyze-history
analyze-history () {
history|awk '{print $2, $3}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -nr|less
}
#END analyze-history
#BEGIN git aliases
alias gs='git status'
function git-log-title-body-only () {
git log --format='%Cgreen%s%n%Creset%b'
}
alias gltbo=git-log-title-body-only
# delete all merged branches
# From https://devconnected.com/how-to-clean-up-git-branches/
alias git-clean-branches='git branch --color=never --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'
# end delete all merged branches
# Begin git cherry-pick alias
alias gcp='git cherry-pick'
# end git cherry-pick alias
# Begin git pull origin master alias
function gpom ()
{
echo 'git pull origin master;'
git pull origin master;
}
# end git pull origin master alias
function gfom ()
{
echo 'git fetch origin master;'
git fetch origin master;
}
# Begin git checkout alias
# alias go='git checkout'
alias gb='git branch'
alias gob='git checkout -b'
# end git checkout alias
alias gu="git commit --amend --no-edit"
alias gr="git add-unmerged; echo 'resolved all'"
# Ignore all files that are currently deleted, forever.
# (https://orangenarwhals.com/2020/12/fun-with-git-how-to-ignore-locally-deleted-files-in-git-status-if-youre-running-out-of-hard-drive-space/)
alias git-ignore-deleted="git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin"
alias git-unignore="git update-index --no-assume-unchanged --stdin"
alias git-see-ignored="git ls-files -v | grep \"^[a-z]\" | sed 's/^[a-z] \(.*$\)/\1/'"
#END git aliases
#### ACCESSING REMOTE FILE SYSTEMS
#BEGIN snowflake scp
function sf-scp () {
if [[ -z $2 ]] ; then
scp [email protected]:"$1" "$1";
else
scp [email protected]:"$1" "$2";
fi
}
#END snowflake scp
#BEGIN infolab ssh
function infolab() { eval "ssh -Y henryhu@$1.csail.mit.edu" ;}
alias nav='infolab navassa'
alias spr='infolab spratly'
alias wal='infolab wallis'
alias enav='emacs -f nav'
alias espr='emacs -f spr'
alias ewal='emacs -f wal'
alias esno='emacs -f sno'
alias erac='emacs -f rac'
alias eath='emacs -f ath'
alias essh='emacs -f ssh'
#END infolab ssh
#BEGIN mount file systems ssh
alias mntbaker="umount -f ~/baker; sshfs henryhu@baker:/usr/local/share/baker/staging ~/baker"
alias mntspratly="umount -f ~/spratly; sshfs [email protected] ~/spratly"
alias mntdevon="umount -f ~/devon; sshfs [email protected]:/storage/henryhu ~/devon"
#END mount file systems ssh
#BEGIN unmount icecube from snowflake
alias umnticecube="diskutil unmount /Volumes/Extreme\ SSD/; diskutil unmount /Volumes/icecube/;"
#END unmount icecube from snowflake
#BEGIN check if ssh server is running
# If output is not empty, then ssh server is active.
alias check-ssh="ps -A | grep sshd"
#END check if ssh server is running
#BEGIN Check my public IP
alias check-ip="dig +short myip.opendns.com @resolver1.opendns.com"
#END Check my public IP
#BEGIN instance var slushy -- computer domain
export slushy="slushy.myddns.me"
#END instance var slushy -- computer domain
#BEGIN slushy ssh
alias slu="ssh -Y [email protected]"
alias sno="ssh -Y [email protected]"
alias flo="ssh -Y [email protected]"
alias nlp="ssh [email protected]"
#END slushy ssh
#BEGIN Shortcut for athena
function athena() {
echo "ssh -Y athena.dialup.mit.edu;"
ssh -Y athena.dialup.mit.edu;
}
alias a=athena
#END Shortcut for athena
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# Use GNU Grep
export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
PATH="/Applications/Julia-1.1.app/Contents/Resources/julia/bin:${PATH}"
export PATH
#curl -s -L http://bit.ly/10hA8iC | bash
#alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs
# Python virtualenvs
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/opt/anaconda3/bin/python3.8;
[ -f /opt/anaconda3/bin/virtualenvwrapper.sh ] && source /opt/anaconda3/bin/virtualenvwrapper.sh
export MACOSX_DEPLOYMENT_TARGET=11.4
# END Python virtualenvs
# Working directory shortcut
source ~/.wd-history
# End working directory shortcut
# Node virtual environments
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# END Node virtual environments
# swap two files
function swap()
{
local TMPFILE=tmp.$$
mv "$1" $TMPFILE && mv "$2" "$1" && mv $TMPFILE "$2"
}
function swap-swap()
{
local TMPFILE=tmp.$$
mv-mv "$1" $TMPFILE && mv-mv "$2" "$1" && mv-mv $TMPFILE "$2"
}
alias sw=swap
alias sw-sw=swap-swap
# END swap two files
function zoomcrop () {
echo "Usage: zoomcrop IN OUT"
ffmpeg -i "$1" -filter:v "crop=2075:1181:0:116" "$2" # crop=w:h:x:y
}
function rm-audio {
ffmpeg -i "$1" -c copy -an "$1-nosound.${1#*.}"
}
function epic-games-non-crash {
open /Applications/Epic\ Games\ Launcher.app --args -ForceMacOldHttpImpl
}
function vnc-tunnel {
# How to connect to malta via VNC:
# vnc-tunnel;
# open VNCViewer and go to Localhost:5901
ssh [email protected] -L 5901:localhost:5901;
# Alternatively:
# ssh -Y wallis.csail.mit.edu;
# wallis:~$ vnc
}
function fix-webcam {
pushd ~/node-uvc-control || return
node ./examples/server.js > /dev/null 2>&1 &
sleep 0.5 # wait for node to start the server
# Don't use https, or else SSL protocol error
chrome "http://localhost:3000/" > /dev/null 2>&1 &
read -r -p "Press enter to kill all node jobs in this terminal session"
echo "Good bye!"
echo "------------"
kill "$(jobs -p node)"
popd || return
}
function for-loop-example {
# field separator
IFS=$(echo -en "\n\b")
for i in $(find .)
do
ffmpeg -i "$i" "$i.mp3"
done
}
function start-ddclient {
# emacs /usr/local/etc/ddclient/ddclient.conf
sudo /usr/local/opt/ddclient/sbin/ddclient -verbose -noquiet
}
function print-betty () {
scp "$1" spratly.csail.mit.edu:~/tmp-to-print;
ssh spratly.csail.mit.edu "lpoptions -d betty && lp tmp-to-print"
}
function print-betty-on-host () {
scp "$1" "$2".csail.mit.edu:~/tmp-to-print;
ssh "$2".csail.mit.edu "lpoptions -d betty && lp tmp-to-print"
}
function concat-pdfs () {
pdftk "$@" cat output out.pdf
echo "Concatenated PDFs "$@" to out.pdf"
}
function pdf-booklet () {
# Print pdf into a booklet form (4 pages per front-back page)
echo "Follow this procedure:"
echo "1. Print from Adobe Acrobat in booklet mode to the network printer: localhost"
echo "2. sudo -s"
echo "3. cd /private/var/spool/cups; ls -lrth"
echo "4. Examine the newest file here named d#####-###"
echo "5. You must do pstopdf d#####-###; chown henryhu *.pdf; mv *.pdf ~henryhu/Downloads;"
}
function forward-devon () {
ssh -L 127.0.0.1:8888:127.0.0.1:8888 devon.csail.mit.edu;
}
function dtach-screen () {
# Use dtach to manage sessions. The issue is that it doesn't save
# output (scrollback), so we just redirect all output. You can
# examine output with action out (perhaps piped into less). You
# can examine the tail of output with action tail.
filename="$1"
if [[ -z $1 ]] ; then
filename='mydtach'
fi
mkdir -p /tmp/dtachsockets/
fullfilename="/tmp/dtachsockets/$filename"
echo "Entering dtach at $fullfilename. To get out, use C-\."
echo "Remember to redirect outputs to log files before detaching >> /tmp/log."
dtach -A "$fullfilename" -r none -z bash
# if [[ $2 == "out" ]] ; then
# cat "$fullfilename.out"
# elif [[ $2 == "" ]] ; then
# # Existing session. attach
# touch "$fullfilename.out"
# # dtach -A "$fullfilename" -r ctrl_l -z bash >> "$fullfilename.out" 2>&1
# elif [[ $2 == "watch" ]] ; then
# # r: interpret colors (call in ansi-term or term only!)
# # f: Force open binary files
# # +F: watch for append.
# less -rf +F "$fullfilename.out"
# elif [[ $2 == "tail" ]] ; then
# tail "$fullfilename.out"
# else
# echo "Usage: dtach-screen [sessionname] [out|watch]"
# fi
}
alias ds=dtach-screen
function fix-emacs () {
# https://emacs.stackexchange.com/questions/21643/what-do-i-do-when-emacs-is-frozen
pkill -SIGUSR2 emacs
# Immediately do M-x toggle-debug-on-quit
}
function wordle () {
pushd ~/Downloads || return
workon astro
python -i wordle.py
}
alias stack-branch="git commit --allow-empty -m"
alias stack-restack="git fetch origin master; git rebase -i origin/master"
alias stack-push-f="yes | ~/stripe/zoolander/create-and-push-pr-stack.sh"