-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_profile
804 lines (578 loc) · 21.2 KB
/
.bash_profile
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# for using het conda installation
#VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/errollloyd/Library/Enthought/Canopy_64bit/User/bin/activate
export EDITOR=vim
export PATH="$(/Users/errollloyd/.dotfiles/custom_path.sh)"
# > Terminal Settings
# vi mode for bash
set -o vi
# bind escape to k+j
# bind '"kj":"\e"'
# allow forward search with reverse search (C-R)
stty -ixon
# > aws tab-complete
# # path to aws-completer
# export PATH=/usr/local/aws/bin:$PATH
# # assigning completer
# complete -C '/usr/local/bin/aws_completer' aws
# for helm@2 (as helm is now on v3, but jupyterHub doesn't support)
# installed via brew
# quick hack that is now probably redundant
# export PATH="/usr/local/opt/helm@2/bin:$PATH"
# export PATH=$PATH:~/abin
# export PATH=/Applications/NEURON-7.4/nrn/x86_64/bin:$PATH #added by NEURON installer
# export PATH="/usr/local/bin:$PATH"
# export PATH="$HOME/bin:$PATH"
# > pythonpath
# Adds my personal script library to pythonpath
export PYTHONPATH=${PYTHONPATH}:~/Dropbox/Science/scripts/
# export PYTHONPATH=${PYTHONPATH}:~/Developer/zekell/zekell_sqlite/
# For terminus in sublime text
bind '"\e[1;3C": forward-word'
bind '"\e[1;3D": backward-word'
# > AWS Default (name) profile
# profile should be defined in ~/.aws
export AWS_DEFAULT_PROFILE=maegul_user
###
# > Prompt
###
# >> check interactive
# Checking if interactive, to prepare prompt only for interactive
# Using .bash_profile and .bashrc more appropriately may make this cleaner
if [[ $- == *i* ]]
then
# Edits prompt
#old
#export PS1="\n(\!)-(\[\e[37m\]\t\[\e[0m\])-(\[\e[31m\]\u\[\e[0m\])-(\[\e[36m\]\w\[\e[0m\])\n> "
# USing git-prompt (semi-official)
# >> git prompt settings
source ~/.dotfiles/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWSTASHSTATE=1
#colors only work if using PROMPT_COMMAND ??
GIT_PS1_SHOWCOLORHINTS=1
# GIT_PS1_SHOWUPSTREAM="verbose"
GIT_PS1_SHOWUPSTREAM="verbose name"
# GIT_PS1_SHOWUPSTREAM="auto"
# >> pushd for prompt
# addings a pushd dirs to prompt when more than one in stack
print_dirs(){
if (($(dirs -v | wc -l) > 1));
then
echo -e "\n$(dirs -v | tail -n +2)";
fi
}
# >> backup check
print_backup_check()
{
time_since=$(backup_since)
if [[ $time_since > 1 ]]; then
echo "(${time_since})"
fi
}
# >> conda env
# check if in conda env, if so return (env)
# used instead of default conda prompt change
# turned off with conda config --set changeps1 false
print_conda_env()
{
if [ -n "$CONDA_DEFAULT_ENV" ]; then
echo "($CONDA_DEFAULT_ENV)"
fi
}
# >> Ranger Level
# if in a subshell from a ranger instance
# retrieve the env "RANGER_LEVEL" (created by ranger, somehow)
# print the number with minor formatting
function ranger_level(){
# local lvl;
# lvl="$RANGER_LEVEL"
if [ "$RANGER_LEVEL" = "" ]; then
echo ""
else
echo "R$RANGER_LEVEL"
fi
}
# >> time symbol
# For converting current time to col idx from file
source ~/.dotfiles/date_cols_test.sh
# unicode for a filled sun symbol and a moon
time_sun_symbol="\xe2\x98\x80"
time_moon_symbol="\xe2\x98\xbe"
print_time_symbol()
{
date_now=$(date +"%H")
if [[ $date_now > 20 && $date_now < 5 ]]; then
time_symbol=$time_moon_symbol
else
time_symbol=$time_sun_symbol
fi
echo -e "$(tput setaf $(date_col_parse))${time_symbol} $(tput sgr0)"
}
# >> tput and color
# Converts RGB coords (6x6x6) to ASNI color code
function RGBcolor {
echo "16 + $1 * 36 + $2 * 6 + $3" | bc
}
# prints the full 6 value deep color palette
function RGBpalette(){
printf "
NNN -> RGB
c = 16 + (R*36) + (G*6) + B
| *--> Blue
| |
| v Green
v
Red\n"
# min and max values
local Rm
local Gm
local Bm
local RM
local GM
local BM
local r
local g
local b
RM=${1:-5}
GM=${2:-5}
BM=${3:-5}
Rm=${4:-0}
Gm=${5:-0}
Bm=${6:-0}
for ((r=$Rm; r<=$RM; r++));
do for ((g=$Gm; g<=$GM; g++));
do for ((b=Gm; b<=$BM; b++));
do tput setaf $(RGBcolor $r $g $b) && tput rev;
msg=" $r$g$b "
if [ $b == $BM ]; then
echo "$msg";
else
echo -n "$msg";
fi
done
done
done;
tput sgr0
}
# >> preddefined colours
# Predefined colors
reset=$(tput sgr0)
bold=$(tput bold)
rev=$(tput rev)
# hist_numberBG=$(tput setab 33)
# hist_number=$(tput setaf 213)
col_BUTime=$(tput setaf 208)
gitPrompt=$(tput setaf "$(RGBcolor 3 0 3)" )
condaEnvCol=$(tput setaf "$(RGBcolor 0 4 1)")
ranger_lvl_Col=$(tput setaf "$(RGBcolor 3 2 3)")
# >> Assembling Prompt
PS1="\n"
# PS1+="\$(echo -e '$(tput setaf $(date_col_parse))${time_sun_symbol}$(tput sgr0) ')"
PS1+="\$(print_time_symbol)"
# ranger level number ... make reversed to it looks different from all the other elements
PS1+="\[${rev}\]"
PS1+="\[${ranger_lvl_Col}\]\$(ranger_level)"
PS1+="\[${reset}\]"
PS1+="\[${bold}\]"
# PS1+="\[${rev}\]"
PS1+="\[${col_BUTime}\]\$(print_backup_check)"
PS1+="\[${condaEnvCol}\]\$(print_conda_env)"
PS1+="\n"
PS1+="\[${gitPrompt}\]\$(__git_ps1 '(%s)')"
PS1+="\[\e[36m\](\w)"
PS1+="\[\e[36;2m\]\$(print_dirs)"
PS1+="\[${reset}\]"
PS1+="\n> "
export PS1
#Old custom git prompt
#parse_git_branch(){ git branch 2>/dev/null | grep '^*' | colrm 1 2;}
#export PS1="\n(\!)-(\[\e[31m\]\u\[\e[0m\])\n(\[\e[36m\]\w\[\e[0m\])-(\[\e[35m\]\$(parse_git_branch)\[\e[0m\])\n> "
# > git autocomplete
# Adds script for git autocomplete
source ~/.dotfiles/.git-completion.bash
# > Terminal Colours
# ANSI escape codes cheat sheet
# 38;5 ... foreground
# 48;5 ... background
# 7 swap background and foreground (useful)
# 1 ... bold
# 4 ... underline
# >> LSColors
export CLICOLOR=1
export LSCOLORS=GaBaBxDxFaegedabagAgAf
# For linux style binaries (translated from LSCOLORS above using https://geoff.greer.fm/lscolors/
#export LS_COLORS='di=1;36;40:ln=1;31;40:so=1;31:pi=1;33:ex=1;35;40:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=1;30;46:ow=1;30;45'
# >> Exa Colours
# dir_color="di=38;5;$(RGBcolor 0 5 5);1;4;48;5;$(RGBcolor 2 0 1)"
#dir_color="di=38;5;$(RGBcolor 0 0 1);1;48;5;$(RGBcolor 0 3 3)"
dir_color="di=1;7;38;5;$(RGBcolor 0 3 3)"
ex_color="ex=38;5;$(RGBcolor 4 0 2);1;4"
link_color="ln=48;5;$(RGBcolor 1 0 1)"
python_script_color="*.py=38;5;$(RGBcolor 1 4 0);1"
jup_nb_color="*.ipynb=38;5;$(RGBcolor 0 3 1);4"
pkl_color="*.pkl=7;38;5;$(RGBcolor 0 3 2)"
markdown_color="*.md=38;5;$(RGBcolor 4 2 3)"
custom_immediate="38;5;$(RGBcolor 4 4 0);1;4"
current_user_color="uu=38;5;$(RGBcolor 3 2 0);1"
user_r_bit="ur=7;38;5;$(RGBcolor 0 4 0);1" # green
user_w_bit="uw=7;38;5;$(RGBcolor 4 4 0);1" # green
user_x_bit="ux=7;38;5;$(RGBcolor 4 0 0);1" # green
user_xd_bit="ue=7;38;5;$(RGBcolor 4 0 0);1" # green
grp_r_bit="gr=38;5;$(RGBcolor 0 4 0);1" # green
grp_w_bit="gw=38;5;$(RGBcolor 4 4 0);1" # green
grp_x_bit="gx=38;5;$(RGBcolor 4 0 0);1" # green
oth_r_bit="tr=38;5;$(RGBcolor 0 4 0);1" # green
oth_w_bit="tw=38;5;$(RGBcolor 4 4 0);1" # green
oth_x_bit="tx=38;5;$(RGBcolor 4 0 0);1" # green
export LS_COLORS="$link_color:so=1;31:pi=1;33:$ex_color:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=1;30;46:ow=1;30;45:$python_script_color:$jup_nb_color:$dir_color:$pkl_color:$markdown_color:*readme*=$custom_immediate:*README*=$custom_immediate:*.todo=$custom_immediate:*.TODO=$custom_immediate:*thoughts*=$custom_immediate"
# for exa specifically
export EXA_COLORS="$current_user_color:$user_r_bit:$user_w_bit:$user_x_bit:$user_xd_bit:$grp_r_bit:$grp_w_bit:$grp_x_bit:$oth_r_bit:$oth_w_bit:$oth_x_bit"
fi
# Add another directory to path, for MRI analysis software
# ??? --- Don't know what this is about, I didn't do it ...
export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:~/abin
# export PYTHONPATH=${PYTHONPATH}:/Applications/NEURON-7.4/nrn/lib/python #added by NEURON installer
# The line below appears unnecessary ... adding anaconda/bin to PATH is sufficient.
# Indeed, the below breaks pip's ability to be environment aware in conda environments
# export PYTHONHOME="/Users/errollloyd/anaconda" #added by NEURON installer
# not sure what this is about or why it's necessary ... my remove
# export LD_LIBRARY_PATH="/Users/errollloyd/anaconda/lib:$LD_LIBRARY_PATH" #added by NEURON installer
# Add User executables to path early so that they override /usr/bin
### this directory should be used by HomeBrew. It should also be added by path_helper through /etc/paths, but in the wrong order. I don't want to muck around with /etc/paths, so Im adding it here. It will probably appear twice in PATH now. :(
# Add personal executables in $HOME/bin to path
# NPM global installs available by require()
export NODE_PATH=/usr/local/lib/node_modules
# > shell options
# extglob - more regex options (?)
shopt -s extglob
# >> history management
# allow preceding whitespace to prevent from being logged in history
HISTCONTROL=ignorespace
HISTSIZE=5000
HISTFILESIZE=20000
shopt -s histappend
# > Aliases
# >> zekell
alias zkl='/Users/errollloyd/Developer/zekell/zekell_sqlite/zekell.py'
# Some alias play ... yay!
# >> File management with ls / eza (successor to exa)
# alias ll='ls -haltF'
# --icons (v>=0.9.0) relies on appropriate fonts
# Currently installed through brew tap cask/homebrew-fonts ... hack-nerd-font and drois-sans-mono font
# But with sequioa, now (15.1) and eza, fonts seem to work out of the box
# "g" prints group ... maybe not that valuable on macOS home machine?
alias ll='eza -la -s=age --git --icons' # basic long form sorted by age (youngest fist)
alias llt='eza -la -s=type --git --icons' # sort by type
alias lltr='eza -la --tree --git --icons -I .git' # tree display, ignore .git folders
alias llext='eza -la -s=extension --git --icons' # sort by extension
# ranger file, when sourced mangles bash to cd to current directory on exit
# while also running ranger
# so alias simply sources from path whatever ranger is
# which should run ranger and return to ranger's last directory on exit
alias rang='source $(which ranger)'
# CLICOLOR_FORCE for BSD/MAC to force ls to provide color chars in output to non terminal
# alias lls='CLICOLOR_FORCE= ll | less -R'
# tree alias with nicer graphics
alias tree='tree -A'
alias cl='clear'
# >> Diffs
alias gdiff='git diff --no-index --word-diff=color -w'
# alias fulldiff='colordiff -y -W 200 --left-column'
fulldiff() {
# provide width as third argument!
colordiff -y -W ${3:-200} --left-column $1 $2 | less -R
}
fulldiff_q() {
# provide width as third argument!
colordiff -y -W ${3:-200} --suppress-common-lines $1 $2 | less -R
}
# >> Network
# list listening ports on local host
alias lslocports="netstat -anp tcp \
| awk '/127.0.0.1.*LISTEN.*/ {print \$4}' | awk -F \".\" '{print \$5}' \
| sort -n"
# >> bash profile
# edit and source bash profile
export USER_BASH_PROFILE_PATH='~/.bash_profile'
alias bpe="vim $USER_BASH_PROFILE_PATH"
alias bpes="subl -n $USER_BASH_PROFILE_PATH"
alias bpsrc="source $USER_BASH_PROFILE_PATH"
# alias py_serve='python -m SimpleHTTPServer'
# python 3 version
alias py_serve='python3 -m http.server'
# >> python test debug with ipython
alias ptidb='pytest --pdbcls=IPython.terminal.debugger:TerminalPdb --pdb -s'
# spartan SSH
alias spartan_ssh='ssh [email protected]'
alias spartan_ssh_io='ssh [email protected]'
# nectar errol-test ssh
alias nectar_ssh='ssh -i ~/.ssh/errolNectarKey2019.pem [email protected]'
# mac pro ssh
alias mac_pro_ssh='ssh [email protected]'
alias mac_pro_hal_ssh='ssh [email protected]'
alias aryabhat_ssh='ssh [email protected]'
alias aws_free_ssh='ssh -i ~/.ssh/id_rsa [email protected]'
alias aws_large_ssh='ssh -i ~/.ssh/id_rsa [email protected]'
alias ssh_hosts="grep 'Host \S' ~/.ssh/config | cut -c 6-"
# project notes todo check
alias todo='/Users/errollloyd/Dropbox/Science/PhD/project_notes/todo_check.sh'
# matlab no desktop alias
alias matlab_cl='matlab -nodesktop -nodisplay -nosplash'
# get current ip address
alias my_ip='ipconfig getifaddr en0'
# Get 12 character SHA of current git HEAD
alias head_sha='git log --pretty=format:%H -1 | cut -c 1-12'
# >> tmux aliases
alias tm="tmux"
# create new named tmux session
alias tm_new="tmux new -s"
# list sessions
alias tm_ls="tmux ls"
# attach to named session
alias tm_at="tmux a -t"
# kill named session
alias tm_kill="tmux kill-session -t"
# Misc Aliases
# sublime text
alias sublime_press_hold_on='defaults write com.sublimetext.4 ApplePressAndHoldEnabled -bool false'
alias sublime_press_hold_off='defaults write com.sublimetext.4 ApplePressAndHoldEnabled -bool true'
## Go to User folder of current sublime text install
alias goto_sublime_user='cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User'
alias goto_lenTun_data='cd /Volumes/MagellanX/PhD/Data/length_tun_data/'
alias goto_proj_notes='cd ~/Dropbox/Science/PhD/project_notes'
# alias for quick debug
alias qlldb='lldb --batch -o run -o bt -o q'
lls() {
CLICOLOR_FORCE= ls -haltF $1 | less -R
}
## volume management aliases
# python charmers volume
alias pychm_mount='diskutil apfs unlockVolume /dev/disk1s5'
alias pychm_unmount='diskutil unmount /dev/disk1s5'
alias jnb_ssh='ssh [email protected]'
## Sendong to Python Charmers AWS Notebook Server by scp
# senf file
jnb_send() {
scp $1 [email protected]:"'/var/www/notebooks/notes/424 Intermediate Best Practices/Errol Lloyd'"
}
# send dir
jnb_send_dir() {
scp -r $1 [email protected]:"'/var/www/notebooks/notes/424 Intermediate Best Practices/Errol Lloyd'"
}
# >> aws aliases
# lif_hws instance shortcuts
alias aws_lif_start="aws ec2 start-instances --profile maegul_user --instance-ids i-056ed6409a99e4022"
alias aws_lif_stop="aws ec2 stop-instances --profile maegul_user --instance-ids i-056ed6409a99e4022"
alias aws_lif_large_start="aws ec2 start-instances --profile maegul_user --instance-ids i-038e6c05f6dee7230"
alias aws_lif_large_stop="aws ec2 stop-instances --profile maegul_user --instance-ids i-038e6c05f6dee7230"
# take from macOS clipboard and set to awsinst
alias aws_copy_ip='export awsinst=$(pbpaste)'
alias aws_qcon='ssh ubuntu@$(pbpaste)'
alias aws_con='ssh ubuntu@$awsinst'
# assumes default profile is pythoncharmers
alias aws_list_running_ec2="aws ec2 describe-instances --query \"Reservations[*].Instances[*].{public_ip:PublicIpAddress,priv_ip:PrivateIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}\" --output table --filters \"Name=instance-state-name,Values=running\""
# requires aws CLI configured for users
# also depends on jq
alias aws_li="aws ec2 describe-instances | jq '.Reservations | .[] | .Instances | .[] | {type: .InstanceType, id: .InstanceId, state: .State.Name, tags: .Tags}'"
alias aws_start="aws ec2 start-instances --profile maegul_user --instance-ids"
alias aws_stop="aws ec2 stop-instances --profile maegul_user --instance-ids"
# presumes single running instance for easy use
aws_running_id() {
aws ec2 describe-instances --profile maegul_user | jq -r '.Reservations | .[] | .Instances | .[] | select(.State.Name=="running") | .InstanceId'
}
# presumes single running instance for easy use
aws_running_dns(){
aws ec2 describe-instances --profile maegul_user | jq -r '.Reservations | .[] | .Instances | .[] | select(.State.Name=="running") | .PublicDnsName'
}
# presumes single running instance
alias aws_running_ssh='ssh ubuntu@$(aws_running_dns)'
# for pychm account
alias aws_li_pychm="aws ec2 describe-instances | jq '.Reservations | .[] | .Instances | .[] | {type: .InstanceType, id: .InstanceId, state: .State.Name, tags: .Tags}'"
alias aws_start_pychm="aws ec2 start-instances --instance-ids"
alias aws_stop_pychm="aws ec2 stop-instances --instance-ids"
# couldn't get at command to work ... otherwise code is probably good
# aws_timed_instance() {
# aws ec2 start-instances --instance-ids $1
# echo "aws ec2 stop-instances --instance-ids $1" | at now + 4 hours
# }
# presumes single running instance for easy use
aws_running_id_pychm() {
aws ec2 describe-instances | jq -r '.Reservations | .[] | .Instances | .[] | select(.State.Name=="running") | .InstanceId'
}
# presumes single running instance for easy use
aws_running_dns_pychm(){
aws ec2 describe-instances | jq -r '.Reservations | .[] | .Instances | .[] | select(.State.Name=="running") | .PublicDnsName'
}
# presumes single running instance
alias aws_running_ssh_pychm='ssh ubuntu@$(aws_running_dns_pychm)'
## Current transitioning conda env to python 3 ... quickly source
# transition complete(?)
# alias pynew='source activate n3w'
# >> jupytext
alias jpt2md='jupytext --to md --from py:light'
alias jpt2py='jupytext --to py:light --from md'
# > Document Tools
# >> markdown to docx
# pandoc function to convert markdown to docx of same filename
md2doc() {
file=$1
pandoc $file -o "${file%.*}.docx"
}
# > Git and Version Control
# nicer issue list with hub
alias hil='hub issue -f "%sC%i%Creset %t %n%Cblue%Nc%Creset%Cmagenta(%au)%Creset%Ccyan(%cD, %ur)%Creset %l%n%n"'
# >> Clone and Fork
# Clones and then forks a GitHub repo
# Relies on hub and ack for regex
gh_fork() {
regex='([\w\d\-]+).git$'
repo_dir="$(echo $1 | ack $regex --output '$1')"
# echo $repo_dir
git clone $1
cd $repo_dir
hub fork
}
# trying a better command with better defaults for the hub cli
gh_fork() {
regex='([\w\d\-]+).git$'
repo_dir="$(echo $1 | ack $regex --output '$1')"
# echo $repo_dir
hub clone $1
cd $repo_dir
# now upstream is "upstream" and personal fork is "origin"
hub fork --remote-name origin
# set upstream for local pushes to origin (personal remote)
git --track origin master
}
# for viewing man pages in vim
vman() {
vim -c "SuperMan $*"
if [ "$?" != "0" ]; then
echo "No manual entry for $*"
fi
}
# > Shell Hacks
# >> quick find
# quick find in current directory
function qfd { find . -iname "*$1*" -print; }
# >> make dir and change dir
# make and change to directory
mkcd()
{
mkdir -- "$1" &&
cd -- "$1"
}
# >> Directory Stack
# aliases for pushd stack usage
# alias pcd='pushd'
pcd_re='^[0-9]+$'
pcd()
{
# If arg is a number, then rotate with + symbol
if [[ "$1" =~ $pcd_re ]] ; then
pushd +"$1" > /dev/null
# Else, push the directory onto the stack
else
pushd "$1" > /dev/null
fi
}
alias dirs='dirs -v'
mkpcd()
{
mkdir -- "$1" &&
pcd "$1"
}
# clear with dirs -c
pcl()
{
if [[ "$1" =~ $pcd_re ]] ; then
popd +"$1" > /dev/null
else
dirs -c
fi
}
# > conda
alias cna='conda activate'
alias cnda='conda deactivate'
alias cnli='conda env list'
# Open safari window and start jupyter notebook kernel
######
# Requires the window to be refreshed
# Relies on an Apple Script to open a new window with a particular URL
# All of this is necessary just to keep the auto open tab behaviour of safari ... there's probably a better way
function jnb {
for n in {0..20}
do let nn=8888+n
if lsof -Pi :$nn -sTCP:LISTEN -t >/dev/null; then
echo "$nn already being used";
else
osascript ~/Library/Scripts/jnb_saf_open.scpt "http://localhost:$nn"
jupyter notebook --port=$nn --no-browser
break
fi
done
}
# > Homebrew
# * It exports some env variables (prefixed with `HOMEBREW`), and compiles and updated `PATH` variable that is also exported
# * It basically puts `/opt/homebrew/bin` and `/opt/homebrew/sbin` ahead of the current path.
eval "$(/opt/homebrew/bin/brew shellenv)"
# > Old kubectl stuff (for pythoncharmers cluster)
# kb_context(){
# kubectl config current-context
# }
# kb_context_list_all(){
# # awkwardly, the first column is empty when not current, so first column is col name for not current
# kubectl config get-contexts | tail -n +2 | awk '{print ($1 == "*" ? FNR "-> " $2 : FNR " " $1)}'
# }
# kb_context_get(){
# # awkwardly, the first column is empty when not current, so first column is col name for not current
# kubectl config get-contexts | tail -n +2 | awk -v x=$1 'FNR == x {print ($1 == "*" ? $2 : $1 )}'
# }
# kb_context_cp(){
# kb_context_get $1 | tr -d '\n'| pbcopy
# }
# kb_context_set(){
# kubectl config use-context $(kb_context_get $1)
# }
# # set current context to use the provided namespace as default
# kb_context_default_namespace(){
# kubectl config set-context --current --namespace=$1
# }
# # scale number of replicas to input (~ number of participants)
# kb_scale_replicas(){
# kubectl scale -n jhub statefulsets/user-placeholder --replicas=$1
# }
# # sort by ip address
# kb_list_all_pods(){
# kubectl get pod -n jhub -o wide | awk 'NR>1{ print $1, $7, $5}' | sort -k 2 | rs _ 3
# }
# # sort by ip address
# kb_list_all_jupyter_pods(){
# kubectl get pod -n jhub -o wide | awk '/jupyter/ NR>1{ print $1, $7, $5}' | sort -k 2 | rs _ 3
# }
# # searches pod names for provided string as 'jupyter-.*STRING.*'
# kb_find_pod_name(){
# # kubectl get pods | awk -v nm="$1" '/jupyter-.*nm.*/ {print $1}'
# kubectl get pods -n jhub | awk -v nm="jupyter-.*$1.*" '$1 ~ nm {print $1}'
# }
# # opens bash terminal on pod provided
# kb_get_pod_shell(){
# kubectl exec -it -c notebook -n jhub $1 -- /bin/bash
# }
# # wrapper around find_pod_name and get_pod_shell
# kb_find_pod_shell(){
# kb_get_pod_shell $(kb_find_pod_name $1)
# }
# # get root shell
# kb_get_pod_shell_root(){
# kubectl ssh -c notebook -n jhub $1 -- /bin/bash
# }
# # run command on all pods
# kb_com_all_pods(){
# kubectl get pod -n jhub | awk '/jupyter/ {print $1}' | parallel -I {} kubectl exec -it -c notebook -n jhub {} -- bash -c "$@"
# }
# # run command as root on all pods
# kb_com_root_all_pods(){
# kubectl get pod -n jhub | awk '/jupyter/ {print $1}' | parallel -I {} kubectl ssh -c notebook -n jhub {} -- $@
# }