-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_bashrc
More file actions
executable file
·962 lines (824 loc) · 33.2 KB
/
Copy path_bashrc
File metadata and controls
executable file
·962 lines (824 loc) · 33.2 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
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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#!/bin/bash
#^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
# Name: $HOME/.bashrc
# Summary: A bloated bash shell config for at least Unix, Linux, Cygwin, WSL2
# and z/OS
#
# Created: 19-May-1998 (Bob Heckel)
# Modified: 08-Sep-2026 (Bob Heckel)
#^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
#----------------
# Generic #{{{1
#----------------
# Test for an interactive shell. There is no need to set anything past this
# point for scp and rcp, and it's important to refrain from outputting anything
# in those cases.
[[ "$-" != *i* ]] && return
# set -o | grep noclobber
# If you change this to "emacs" a kitten will die:
set -o vi
set -o noclobber
# C-S=suspend C-Q=release bypass
stty -ixon
# Tab completion after typing 'cd ' show dirs only. See also FIGNORE for related completion restrictions.
complete -d cd
shopt -s extglob
shopt -s histappend # append, don't overwrite
# Make fscking dark blue readable
printf '\e]4;4;#6495ed\a'
#-----------------------
# Generic Export #{{{2
#-----------------------
export EDITOR=vi
export GIT_CEILING_DIRECTORIES=/home
# For PS1 function
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
export GIT_EDITOR=vim
HISTSIZE=40000 # max in RAM
HISTFILESIZE=40000 # max lines in $HISTFILE
HISTIGNORE='f:fg:l:ls:la:cd:h:ll::by' # ':&' supposedly same as HISTCONTROL=ignoredups - consecutive dups that is
HISTCONTROL=ignoredups:erasedups
# $ history|sort|grep '2026-07-16 1'
HISTTIMEFORMAT='%F %T '
IGNOREEOF=1 # require 2 ctr-d to exit
export LESS='--ignore-case' # but still honors 'ThisSearchPattern'
# Prevent ugly default bolding
###export LS_COLORS='*.swp=00;35:*.swo=00;35:*.bak=00;35:ex=00;32:*.java=00;32:*.pm=00;32:no=00:fi=00:di=01;34:ln=00;36:*.lnk=00;36:*.gz=00;31:*.bz2=00;31:*.zip=00;31:*.tgz=00;31:*.7z=00;31'
export LS_COLORS='ow=01;34:tw=01;34:st=01;34:*.swp=00;35:*.swo=00;35:*.bak=00;35:ex=00:*.tar=00;31:*.gz=00;31:*.bz2=00;31:*.zip=00;31:*.tgz=00;31:*.7z=00;31'
export PAGER=less # for man(1)
#PARINIT='rTbgqR B=.?_A_a Q=_s>| w65' # par formatter
# PATH=$PATH:~/bin
export PERLLIB=$HOME/perllib
export PROMPT_COMMAND='echo -ne "\033]0;${PWD}\007";'
export TMP=$HOME/tmp
# Default "unknown host" indicator for my .vimrc statusline
export VIMSTATUSL='?@?'
# Terminal font colors
# Used by PS1, also good for use in shell scripts. But bad for printing env.
# Ctrl-v escape to insert the ^[ because "\[\033[01;38;5;52m\]" won't work.
# Use this to find e.g. 243 for darkgray: for i in {0..255} ; do printf "\x1b[38;5;${i}mcolour${i}\n"; done;
export fg_whitebold="[1;37m"
export fg_lightgray="[0;37m"
export fg_lightgraybold="[1;37m"
export fg_darkgray="[0;38;5;243m"
export fg_darkgraybold="[1;38;5;243m"
export fg_blue="[0;34m"
export fg_bluebold="[1;34m"
export fg_green="[0;32m"
export fg_greenbold="[1;32m"
export fg_cyan="[0;36m"
export fg_cyanbold="[1;36m"
export fg_red="[0;31m"
export fg_redbold="[1;31m"
export fg_magenta="[0;35m"
export fg_magentabold="[1;35m"
export fg_yellow="[0;33m"
export fg_yellowbold="[1;33m"
export normal="[0m"
#-----------------------
# Generic Alias #{{{2
#-----------------------
alias ..='cd ..'
alias bc="bc -lq" # allow floating point calcs, mess up other stuff
alias be="vi $HOME/.bashrc"
alias bgrep="$HOME/code/scripting/bgrep"
alias by=exit # keepin' up the FTP tradition
alias bye=exit
alias cd..='cd ..; ls'
alias cdc="cd $HOME/code"
alias cdd="cd $HOME/code/database"
alias cdo="cd $HOME/dotfiles"
alias cdot="cd $HOME/dotfiles"
alias cdm="cd $HOME/code/misc"
alias cds="cd $HOME/code/sas"
alias cls=clear
alias datecalc="$HOME/code/scripting/datecalc"
alias ddg='w3m http://duckduckgo.com/lite'
alias f='fg' # jobs -s to list what's suspended
alias g=$HOME/dotfiles/gone.sh
alias ga="$HOME/code/misc/gitall"
#alias gafix='(cd ~/code && git merge && git push ; cd ~/dotfiles && git merge && git push; git remote show origin)'
alias gafix='(cd ~/code && git merge && git push ; cd ~/dotfiles && git merge && git push)'
alias gb='for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr\t%an\t" $branch | head -n 1` \\t$branch; done | sort -r'
alias gbc='gnome-terminal -- bc 1>/dev/null'
alias gitall="$HOME/code/misc/gitall"
alias gpul='git pull'
alias gs='git status'
alias gsl='git stash list'
alias h='history|tail -n20'
alias ha='history -a' # append this hist to others
alias hr='history -n' # read in hist from others
alias j="jobs -s" # only show STOPPED (e.g. skip RUNNING blink.exe &) jobs
alias l='ls'
alias la='ls -FA --color=auto' # overridden later if non-GNU ls is present
alias lastdocker='docker start -a -i `docker ps -q -l`'
alias ls='ls --color --group-directories-first'
alias ll='ls -gh --color --group-directories-first'
alias lla='ls -agh --color --group-directories-first'
alias lsd='find . -maxdepth 1 -type d' # list directories
alias m=less
alias one="vi $HOME/dotfiles/oneliners.txt"
#alias plinstall='perl Makefile.PL && make && make TEST_VERBOSE=1 test && make install'
alias qr="$HOME/code/misc/quickref_find.sh"
alias robots="export ROBOTOPTS=moveheaps,showscores,screwdriver,fastrobots; robots" # Good luck Yoshimi...
#alias sasrun=$HOME/code/sas/sasrun
alias sdf='ssh -l bheckel sdf.org; date'
alias sl='ls --color=none' # dyslexic daim branage
alias sr="$HOME/code/sas/sasrun2"
alias srcb="source $HOME/dotfiles/_bashrc"
#alias tmls='tmux list-sessions'
#alias tmux='tmux -u' # UTF8
alias tre="\ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'" # if tree isn't installed
alias uvi="$HOME/code/scripting/uvi" # don't change timestamp
alias ve="vim $HOME/.vimrc"
alias vi=vim
# Quick diff
alias d1="vim $TMP/1 $TMP/2"
alias d2="vim $TMP/2"
alias d12="(cd $TMP; rm 1 2; touch 1 2; vi -c 'map q :qa<CR>' -d 1 2)"
alias d13="(cd $TMP; vi -Rd 1 3)"
alias d123="(cd $TMP; vi -Rd 1 2 3)"
alias d34="(cd $TMP; rm 3 4; touch 3 4; vi -c 'map q :qa<CR>' -d 3 4)"
#-----------------------------------
# bash functions must precede calls
# Generic Functions #{{{2
#-----------------------------------
function ubust() {
local target="${1:-.}"
if [ -d /mnt/c/Windows ]; then
explorer.exe "$target"
else
pcmanfm "$target"
fi
}
# A Windows-ish Start to open a file or file manager
case "$OSTYPE" in
cygwin) st() { explorer "${1:-.}"; } ;;
linux-gnu) st() { ubust "${1:-.}"; } ;;
darwin*) st() { open "${1:-.}"; } ;;
linux-android) st() { termux-open "${1:-.}"; } ;;
netbsd) st() { echo 'no can do, man'; } ;; # avoid "Unknown" message on sdf login
# *) echo '.bashrc: Unknown file manager' >&2 ;;
esac
# cd lazy
cdl(){
command cd "$@" && command ls;
}
# Overly complex Recycler to ReMoVe files we're not yet man enough to delete
# TODO don't write a partial MARKER on failure
rmv() {
local VERBOSE
local MARKER
local __TMP
MARKER=_DELETE
# We don't want /tmp as the rmv dir
__TMP=$TMP
[ "$__TMP" = /tmp ] && __TMP=/$USER/tmp
[ "$__TMP" = //tmp ] && __TMP=/$USER/tmp # double slash is due to root's home '/'
[ "$__TMP" = '' ] && __TMP=/$USER/tmp
[ "$__TMP" = / ] && __TMP=/$USER/tmp
# -s placeholder file output is used for synching home and work
if [ ! "$1" ]; then
echo 'error: Must enter file(s) or file pattern. Exiting.'
echo 'Usage: rmv [-s|-v] file1 file2 pat* ...'
echo " Removes a file or files to $HOME/tmp"
echo " -s places a $MARKER marker after removing (sweep-away-sync mode)"
echo " Must be in pwd for this command to place marker properly"
echo " -v verbose mode"
return 1
fi
if [ "$1" = '-s' ]; then
shift
for f in "$@"; do
if [[ $f =~ ./.* ]]; then
echo 'Cannot use fully qualified paths with -s, please cd first'
else
touch "${f}${MARKER}"
echo "... marker ${f}${MARKER} placed"
fi
done
fi
if [ "$1" = '-v' ]; then
VERBOSE=$1
shift
else
VERBOSE=''
fi
if [ -d $__TMP ]; then
for f in "$@"; do
mv $VERBOSE "$f" $__TMP || echo 'failed to rmv'
done
else # rare
echo "uh oh $HOME/tmp does not exist ... attempting to mkdir ..."
mkdir $HOME/tmp
if [ -e $HOME/tmp ]; then
echo "... success ... try again now"
else
echo "ERROR: cannot create $HOME/tmp"
fi
fi
}
# For PROMPT_COMMAND. 22-Mar-11 deprecated, use \j where possible
stoppedjobs() {
jobs -s | wc -l | sed -e "s/ //g"
}
# Build a disposable sandbox
sbx() {
# Leading epoch date is for sorting purposes. To navigate do something like: cd ~/tmp/*09Jun*
todayuniq=`date +%s_%d%b%y`$1
mkdir $HOME/tmp/$todayuniq
cd $HOME/tmp/$todayuniq
pwd
}
# Last ten
lt() {
if test "x$1" = "x"; then
\ls -lt | head -n10
else
\ls -lt "$1" | head -n10
fi
}
parse_git_dirty() {
GS_PS1=$(git status 2>/dev/null | tail -n1)
[[ ${GS_PS1:0:17} != 'nothing to commit' ]] && echo '*'
}
# To avoid 'parse_git_branch: command not found' `$ sudo visudo` and remove PS1 & PS2
parse_git_branch() {
# Assumes export GIT_DISCOVERY_ACROSS_FILESYSTEM=1 to avoid slowness on network drives
local _tmp=$( git status 2>/dev/null | head -n1 )
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1${fg_redbold}$(parse_git_dirty)${fg_darkgray}]/"
#TODO
# [[ $_tmp = 'On branch develop' ]] && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1${fg_redbold}$(parse_git_dirty)${fg_darkgray}]/"
# [[ $_tmp != 'On branch develop' ]] && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
# curr_git_branch
}
# For informational searches e.g. $ google oracle error codes
function urlencode() { echo -n $@ | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'; }
function goo() { w3m http://www.google.com/search?q="`urlencode $@`" ;}
function google() { w3m http://www.google.com/search?q="`urlencode $@`" ;}
# Paywall jumper vi ~/bin/termux-url-opener termux-open http://www.google.com/search?q="cache:$@" ;
function gooc() { w3m-open http://www.google.com/search?q="cache:`urlencode $@`" ;}
gl() {
# local filebranch=$1
# test "x$filebranch" = "x" && filebranch='CURRENT BRANCH'
local days=$2
test "x$days" = "x" && days=30
git log --pretty=format:"%Cblue%h %ar |%Cgreen %s%Cblue %d [%an]" \
--graph \
--date=short $1 \
|sed "s/^\* //g" \
|head -n$days; \
#echo -n; echo; echo "${fg_darkgray} ...displaying last $days $filebranch";
echo -n; echo; echo "${fg_darkgray} ...displaying last $days days";
}
md() {
mkdir ${1} && cd ${1} && ls -l
}
# Create new tmux session with preconfigured window splits
tmn() {
# Defaults
numpanes=${1:-1}
sesnm=`date +%d%b_%H%M%S`
echo "Opening ${numpanes} pane(s) in session ${sesnm}"
if [ ${numpanes} -eq 2 ]; then
# Two vertical panes
# tmux new -s "s${1}"\; split-window -h
tmux new -s "2|${sesnm}"\; split-window -h
elif [ ${numpanes} -eq 4 ]; then
# Four panes
tmux new -s "4|${sesnm}"\; split-window -v \; split-window -h \; select-pane -t 0 \; split-window -h
else
tmux new -s "${sesnm}"
fi
}
bak() {
if [ -e $HOME/code/misc/bak ];then
$HOME/code/misc/bak ${1}
else
cp -v ${1} ${1}.bak
fi
}
# If locate() is not available
function loc() {
# find $HOME/code | grep -i "${1}" | grep -v '\.git' | xargs ls -ltG >|/tmp/.loc && vim -c "/${1}" /tmp/.loc
find $HOME/code | grep -i "${1}" | grep -v '\.git' >|/tmp/.loc$$.grep && vim -R /tmp/.loc.grep
}
# Find/search my README files by title
function rme() {
find $HOME/code/rme | grep -i "${1}" | grep -v '\.git' >|$HOME/tmp/.rme$$.grep && vim $HOME/tmp/.rme$$.grep
}
function gdt() {
if [ $# -eq 1 ];then
# git diff the last 2 commits for a file
oldhash=$(git log --pretty=format:"%h %ar | %s %d [%an]" --graph --date=short ${1} | sed "s/^\* //g" | head -n2 | head -n1 | awk '{print $1}')
newhash=$(git log --pretty=format:"%h %ar | %s %d [%an]" --graph --date=short ${1} | sed "s/^\* //g" | head -n2 | head -n2 | awk '{print $1}' | tail -n1)
hashes="${oldhash}:./${1} ${newhash}:./${1}"
git difftool $hashes
elif [ $# -eq 2 ];then
# Choose 1 of N commits (other than MRU) to do a copy/paste git difftool
git log --pretty=format:"%h: %ar"\
--date=short ${1} \
| head -n${2} \
| sed "s/:/:\.\/${1} ${1} #/" \
| sed "s/\(.*\)/git difftool \1/" \
| awk "{if (NR>1) print}"; \
echo -n;
else
echo 'Usage: gdt FILENAME [# of commits in past]'
fi
}
function gitup() {
MSG=${1:-mod gitup}
#echo "git add . && git commit -m ${MSG} && git push"
git add . && git commit -m"${MSG}" && git push
}
function fin() {
if [ $# -eq 1 ];then
find . -maxdepth 1 -iname "*${1}*"
elif [ $# -eq 2 ];then
find . -iname "*${2}*"
fi
}
# function stk() {
# # Screenscrape
# w3m -dump https://finance.yahoo.com/quote/${1}%3Fp=${1}/ | grep --after-context=3 watchlist | tail -n2
# }
# function exd() {
# ticker=$(echo $1 | tr [a-z] [A-Z])
# # Screenscrape
# w3m -dump https://finance.yahoo.com/quote/${ticker} | grep Ex-Dividend
# }
# s=cf; stk $s; exd $s; opt $s 210219 045
# function opt() {
# ticker=$(echo $1 | tr [a-z] [A-Z])
# #w3m -dump https://finance.yahoo.com/quote/${ticker}/options?strike=${2}&straddle=false | grep CF2#"^${ticker}"
# echo -n 'short call '
# #%w3m https://finance.yahoo.com/quote/CF210219C00044000 |grep Bid
# w3m https://finance.yahoo.com/quote/${ticker}${2}C00${3}000 |grep Bid
# echo -n 'long put '
# w3m https://finance.yahoo.com/quote/${ticker}${2}P00${3}000 |grep Ask
# }
function divcol() {
id=$(cat ~/bin/td_apikey)
curl -X GET --header "Authorization: " "https://api.tdameritrade.com/v1/marketdata/${1}/quotes?apikey=${id}" | jq '.[] | {bidPrice: .bidPrice, mark: .mark, askPrice: .askPrice, divAmount: .divAmount, divAmount: .divAmount, divYield: .divYield, divDate: .divDate}'
# sed 's/"ct"/Current/; s/"fl"/Feels Like/; s/"hu"/Humidity/; s/"uv"/UV/; s/"ws"/Wind/; s/"wr"/Weather/; s/"sr"/Sunrise/; s/"ss"/Sunset/; s/"pop1"/Precip Probability 1 hr/; s/"pop2"/Precip 2 hr/' \
# ~/tmp/w
}
function stash() {
msg=${1:-saved `date`}
git stash save --include-untracked --message "$msg"
}
# Generic Functions end
#-------------------
# Cygwin #{{{1
#-------------------
case "$OSTYPE" in
CYGWIN*|cygwin*)
echo '.bashrc: Cygwin detected'
# mintty bug hack workaround for changing gray text to black on first execution of external programs
# touch $$ && clip.exe < $$ && rm $$
#-------------------
# Export Cygwin #{{{2
#-------------------
# For drives not mounted by Cygwin
export c=/cygdrive/c/
export cu=/cygdrive/c/Users/$USER
export CYGWIN=nodosfilewarning # MS-DOS style path detected: u:/tmp/bdfCURR.rtpsh005
# export CVSROOT=$HOME/repository
export EDITOR=vim
export LANG=en_US
# Lowercase Windows hostnames
export LCHOSTNAME="`echo ${HOSTNAME} | tr [A-Z] [a-z]`"
# The echo -ne "\033]0;${PWD}\007" causes rxvt titlebar to show PWD.
# '\[ ... \]' says "ignore this material while calculating the size of the prompt".
# Want our history appended (-a) and other term's history merged into ours (-n)
# export PROMPT_COMMAND='history -a; echo -ne "\033]0;${PWD}\007";'
# TODO remove need for LCHOSTNAME for Cygwin, move to generic section
export PS1='${fg_darkgray}\j ${fg_greenbold}\u@${LCHOSTNAME}${fg_darkgray}$(parse_git_branch) \w/ \d \t ${normal} \n\$ '
export PS2=' ' # allow multiple line copy to clipboard
# export SENSIBLE_BROWSER='/cygdrive/c/Program\ Files/mozilla\ firefox/firefox.exe'
#export TERM=mintty
# Only way to get color ls (bug?). Assumes Terminal is set to mintty in mintty Settings.
export TERM=screen-256color
export VIMSTATUSL="${USERNAME}@`echo ${HOSTNAME} | tr [A-Z] [a-z]`"
#-------------------
# Functions Cygwin #{{{2
#-------------------
function putclip() {
#powershell.exe -Command "Set-Clipboard $1"
echo "${1}" | clip.exe
}
#TODO
function catput() {
#powershell.exe -Command "Get-Content $1 | Set-Clipboard"
clip.exe < "${1}"
}
# end Functions Cygwin
#-------------------
# Alias Cygwin #{{{2
#-------------------
alias f='fg'
###alias h='history|tail -20|perl -pe "s/(\d+)(.*)/: \1; \2/"'
alias l='ls -GFw80 --color=none' # for speed on Cygwin
# Eliminate . .., owner and group info on Cygwin
alias ll='ls -FloGgh --color=auto'
alias lla='ls -FlAoh --color=auto'
alias m="less -FRSX" # don't use less if it fits in the window
# Present Working Windows Directory
alias pwwd='cygpath -w "`pwd`"'
###alias sas8="c:/Program\ Files/SAS\ Institute/SAS/V8/sas.exe"
###alias sas9="c:/Program\ Files/SAS/SAS\ 9.1/sas.exe"
alias vi=vim
# Avoid nullglob or e.g. ls k* will show all files if no k* files exist.
shopt -s cdspell checkhash checkwinsize cmdhist huponexit \
histappend cdable_vars
###stty erase ^H intr ^C kill ^K
# umask 022
;; # end Cygwin
#------------------
# SunOS #{{{1
#------------------
'SunOS')
#------------------
# Export SunOS #{{{2
#------------------
export EDITOR=vi
# Set colors in set_prompt_colors(), not here.
###export PS1='\[${fg_darkgray}\]:\[${normal}\] `stoppedjobs`\[${prompt_beg}\]$USER@${HOSTNAME:0:8}\[${prompt_end}\]\[${fg_green}\]\$\[${fg_darkgray}\];\[${normal}\] '
###export PS1=':`stoppedjobs`$USER@${HOSTNAME:0:8}; '
export PS2=' ' # allow multiple line copy to clipboard
export VIMSTATUSL="${USER}@`echo ${HOSTNAME} | tr [A-Z] [a-z]`"
#--------------
# Alias SunOS #{{{2
#------------------
alias l='ls -F'
alias la='ls -FA'
alias ls='ls -F'
alias ll='ls -Fl'
alias lla='ls -FlA'
# Box specific differences:
if [ $HOSTNAME = 'sunstat' ]; then
alias sas='/apps/sas912/sas'
else
alias sas='/apps/sas8.2/sas'
alias sas8='/apps/sas8.2/sas'
alias sas9='/apps/sas912/sas'
fi
if [ $HOSTNAME = 'buddha' ]; then
# Leave / as root's home for things like .Xauthority, etc.
export LD_LIBRARY_PATH=/opt/sfw/lib:/opt/csw/lib:/usr/local/lib
export PATH=$PATH:/opt/bin:/opt/sfw/bin:/opt/csw/bin:/usr/ccs/bin
# TODO run once only and only if X is running, but don't think it's
# more than an annoyance if left as is
/usr/openwin/bin/xmodmap /opt/share/xmodset
alias hf='hiber -nm off'
alias ho='hiber -nm on'
alias ls='gls -F --color'
# Assumes this has been run first
# LD_LIBRARY_PATH=/opt/mozilla/lib:/opt/sfw/lib:/opt/csw/lib
# TODO LD_LIBRARY_PATH won't work inside shell script, must run from
# command line like this:
# export LD_LIBRARY_PATH=/opt/mozilla/lib:$LD_LIBRARY_PATH && moz
###alias moz=/opt/mozilla/mozilla
alias x='rxvt -sr -sk -cr green -pr blue -sl 999 -fn "-sun-*-*-*-*-12-*-*-*-*-*-*-*-*" -bg black -fg wheat -geometry 80x33 -e bash -i'
fi
if [ $HOSTNAME = 'daeb' ]; then
export PATH="$HOME/bin:/opt/bin:/usr/bin:/usr/local/bin:/bin:/opt/sfw/bin:/usr/ucb/:/usr/ccs/bin:/opt/mysql/bin"
# Used at least by 'Bash Prompt Here'
export USER=`/usr/ucb/whoami`
# For at least mysql
export LD_LIBRARY_PATH=/opt/sfw/lib
export MANPATH=$MANPATH:/opt/man:/opt/sfw/man:/usr/openwin/man
# Run system check every other day
if [ `date | awk '{print $3}' | perl -e '$x=<>; $y=($x%2); END{print $y}'` = 0 ]; then
echo
\ls -l /opt/apache/logs/*_log
echo
df -k
echo
uptime
who
echo
last|grep -v bheckel|head -9
fi
fi
stty erase ^? intr ^C kill ^K
shopt -s cdspell
umask 027
;; # end SunOS
#------------------
#-------------------
# Linux #{{{1
#-------------------
linux-* | Linux)
shopt -s cdspell checkhash checkwinsize cmdhist dotglob histappend
stty erase ^? intr ^C kill ^K
#----------------
# Export Linux #{{{2
#----------------
export PATH=~/bin:$PATH
# export PROMPT_COMMAND='history -a; echo -ne "\033]0;${HOSTNAME:0:4}:${PWD}\007";'
# red highlight search results
export LESS_TERMCAP_so=$'\E[01;31m'
export LESS_TERMCAP_se=$'\E[0m'
#TODO avoid 'root@host:~-bash: parse_git_branch: command not found' this doesn't work
#if [[ $EUID -ne 0 && "$(id -u)" -ne 0 ]]; then
if [ $HOSTNAME = 'webserver' ]; then
export PS1='${fg_darkgray}\j ${fg_bluebold}\u@${HOSTNAME}${fg_darkgray}$(parse_git_branch) \W/ \d \t ${normal} \n\$ '
elif [ $HOSTNAME = 'evolved' ]; then
export PS1='${fg_darkgray}\j ${fg_magentabold}\u@${HOSTNAME}${fg_darkgray}$(parse_git_branch) \W/ \d \t ${normal} \n\$ '
elif [ $HOSTNAME = 'sandcastle' ]; then
export PS1='${fg_darkgray}\j ${fg_yellowbold}\u@${HOSTNAME}${fg_darkgray}$(parse_git_branch) \W/ \d \t ${normal} \n\$ '
else
export PS1='${fg_darkgray}\j ${fg_greenbold}\u@${HOSTNAME}${fg_darkgray}$(parse_git_branch) \W/ \d \t ${normal} \n\$ '
fi
#fi
export SYSTEMD_EDITOR=vim
export TEMP=/tmp
#TERM=screen-256color
export TERM=xterm-256color
export VIMSTATUSL="${USER}@`echo ${HOSTNAME}`"
# For crontab -e
export VISUAL=vim
#----------------
# Alias Linux #{{{2
#----------------
#alias hiber='pkexec xfce4-pm-helper --hibernate && sleep 3 && sudo tlsdate -V -H encrypted.google.com'
alias ll='ls -lh --color --group-directories-first'
###alias moz='export DISPLAY=158.111.250.170:0.0; mozilla&'
###alias sqlplus=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/sqlplus
# Print Windows Working Directory. $ pwd|sed 's/\//\\/g'" before backslashitis.
alias pwwd="pwd|sed 's/\\//\\\\/g'"
alias sv="sudo vim -u ~/.vimrc "
alias svim="sudo vim -u ~/.vimrc "
#----------------
# Functions Linux #{{{2
#----------------
function get_distro() {
if [[ -f /etc/os-release ]]; then
source /etc/os-release
echo "$ID"
else
uname
echo wtf
fi
}
case "$(get_distro)" in
ubuntu) echo ".bashrc: Ubuntu detected";;
fedora) echo ".bashrc: Fedora detected";;
debian) echo ".bashrc: Debian detected";;
Darwin) echo ".bashrc: macOS detected";;
ol) echo ".bashrc: Oracle detected";;
*) echo ".bashrc: unknown distro";;
esac
myclip() {
iconv -f utf-8 -t utf-16le | clip.exe
}
# Capture an entire file, otherwise see putclip
function catput() {
if [ -e /usr/bin/xclip ]; then
xclip < "$1"
elif [ -d /mnt/c/Windows ]; then
# clip.exe < "$1"
myclip < "$1"
else
echo "xclip or clip.exe not installed"
fi
}
function distro() {
# cat /etc/*-release | grep VERSION | perl -pe 's/VERSION="//g' | head -n1
cat /etc/*-release
}
function putclip() {
if [ -e /usr/bin/xclip ]; then
echo "${1}" | xclip
elif [ -d /mnt/c/Windows ]; then
echo "${1}" | clip.exe
else
echo "xclip or clip.exe not installed"
fi
}
#----------------
# Ubuntu #{{{1
#----------------
if [[ -f /etc/os-release ]]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" ]]; then
alias systeminfo='df -h && echo && free -m && echo && grep --color="never" name /proc/cpuinfo | uniq && echo && lspci | grep --color="never" VGA && echo && xrandr | grep --color="never" connected && echo && uname -rms'
alias usb='sudo fdisk -l; mount|grep "^/dev/sd"; sudo mkdir /media/usb; echo; echo "try this: sudo mount -t vfat /dev/sdb /media/usb -o uid=1000,gid=1000,utf8,dmask=027,fmask=137"; echo; echo "usually /dev/sdb or sdc, disconnect: sudo umount /media/usb"'
if [ $HOSTNAME = 'yoniso' ]; then
alias cdrom='sudo mount -t iso9660 /dev/cdrom /media/cdrom; mount|grep "^/dev/cd"; echo "sudo umount /media/cdrom"'
alias kindle='sudo mount -t vfat /dev/sdb /media/kindle -o uid=1000,gid=1000,utf8,dmask=027,fmask=137; mount|grep "^/dev/sd"; echo "sudo umount /media/kindle"'
alias nexus='sudo mount -t vfat /dev/sdb /media/nexus -o uid=1000,gid=1000,utf8,dmask=027,fmask=137; mount|grep "^/dev/sd"; echo "sudo umount /media/nexus"'
fi
if [ $HOSTNAME = 'appa' ]; then
alias brinno='sudo mount -t vfat /dev/sdb1 /media/brinno/ -o uid=1000,gid=100,utf8,dmask=027,fmask=137'
alias ubrinno='sudo umount /media/brinno'
alias sandisk='sudo mount -t vfat /dev/sdc /media/sandisk/ -o uid=1000,gid=100,utf8,dmask=027,fmask=137'
alias usandisk='sudo umount /media/sandisk'
fi
# For ~/.fluxbox/menu. Keep terminal open.
if [ -n "$RUNCMDFLUXBOX" ]; then
eval "$RUNCMDFLUXBOX"
unset RUNCMDFLUXBOX
fi
fi
fi
#----------------
# WSL # {{{1
#----------------
if uname -r | grep -qi microsoft; then
echo "WSL detected"
export TEMP=/mnt/c/temp
# Windows Terminal vim syntax bugfix
export TERM=screen-256color
case ":$PATH:" in
*":/mnt/c/Users/bheck/AppData/Local/Android/Sdk/platform-tools:"*) ;;
*) PATH="$PATH:/mnt/c/Users/bheck/AppData/Local/Android/Sdk/platform-tools" ;;
esac
fi
#----------------
# ChromeOS #{{{1
#----------------
if [ $HOSTNAME = 'chromeos' ]; then
sudo mount -i -o remount,exec /home/chronos/user
cd ~
# Optionally start Dropbox if it's not running.
# http://gabeortiz.net/2011/how-to-get-dropbox-working-on-a-cr48-google-chrome-netbook/
if [ -z "$(pgrep dropbox)" ] && [ -d ~/.dropbox-dist ]; then
echo -n 'Start Dropbox? '
read yn
if [ "$yn" = 'y' ];then
~/.dropbox-dist/dropboxd &
fi
fi
# export VIMRUNTIME=/home/chronos/user/.vim
elif [ $HOSTNAME = 'penguin' ];then
function catput() {
buf=$(cat ${1})
# Mask for printf
buf2=$(echo ${buf} | sed 's/%/%%/')
# Also add \r if it's a unix formatted file otherwise it's a single line when clipped
#TODO not working
buf3=$(echo ${buf2} | sed 's/\012/\015\012/g')
#TODO how to tell if TMUX is running IN THIS TERMINAL not just anywhere
#TODO does it matter if we're in tmux? or is there a /dev/pts/1... ?
# if [ -n ${TMUX} ];then
# echo 'tmux printf...'
# printf "\033]52;c;$(printf "${buf2}" | base64 -w0)\a" >/dev/pts/0
printf "\033]52;c;$(printf "${buf3}" | base64 -w0)\a" >/dev/pts/0
# else
# echo 'printf...'
# printf "\033]52;c;$(printf "${buf2}" | base64 -w0)\a"
# fi
}
# Hack for missing clipboard support
# alias cb='echo do v yx on this to clipboard it on chromebook; gvim ~/.crouton-clipboard/data.txt'
function cb(){
echo in vim do v yx on this to clipboard it on chromebook: gvim ~/.crouton-clipboard/data.txt
catput ~/.crouton-clipboard/data.txt
echo or use the carriage return-less version just copied
}
fi # ChromeOS
# Android # {{{1
if [ $HOSTNAME = 'localhost' -a $HOSTTYPE = 'aarch64' ]; then
echo '.bashrc: Android detected'
alias cdd="cd $HOME/downloads"
# When $HOME/code/misc/gitall isn't available
alias gital='cd ~/dotfiles && git add . && git commit -m"mod gitall termux" && git push; git pull; cd -'
alias nb='newsboat -q -r'
alias pa='termux-media-player pause'
alias pl='termux-media-player play'
# Screenscrape TODO need function
alias schd='w3m -dump https://finance.yahoo.com/quote/SCHD%3Fp=SCHD/ | grep --after-context=4 watchlist | tail -n3 | termux-toast'
function catput() {
echo 'termux-clipboard-set...'
cat ${1} | termux-clipboard-set
}
# Instead of cloning my github repo...not sure if thousands of files is
# a problem on Android
function gh() {
if [ $# -eq 0 ]; then
# Jump down to the repo "folders"
w3m -num +165 https://github.com/bheckel/code
elif [ $# -eq 2 ]; then
# Direct to a file $ gh rme termux.txt
w3m -num https://github.com/bheckel/code/raw/master/${1}/${2}/
else
echo 'usage: gh [section] [filename]'
fi
}
function tbak() {
cd /data/data/com.termux/files && \
tar cfz /sdcard/termux.bak.tgz home usr
# TODO encrypt and move tarball to Gdrive
}
function ts() {
termux-share -a send "${1}"
}
function w() {
id=$(cat ~/bin/wapi_key)
#curl --no-progress-meter "https://api.openweathermap.org/data/2.5/onecall?lat=35.92115428&lon=-78.5754912&include=hourly&appid=${id}&units=imperial" | jq '[.| {ct: .current.temp, fl: .current.feels_like, hu: .current.humidity, uv: .current.uvi, ws: .current.wind_speed, wr: .current.weather[0].description, sr: .current.sunrise | strflocaltime("%%%H:%%%M:%%%S %%%Z"), ss: .current.sunset | strflocaltime("%%%H:%%%M:%%%S %%%Z"), pop1: .hourly[0].pop, pop2: .hourly[1].pop}]'
curl --no-progress-meter "https://api.openweathermap.org/data/2.5/onecall?lat=35.92115428&lon=-78.5754912&include=hourly&appid=${id}&units=imperial" | jq '[.| {ct: .current.temp, fl: .current.feels_like, hu: .current.humidity, uv: .current.uvi, ws: .current.wind_speed, wr: .current.weather[0].description, sr: .current.sunrise | strflocaltime("%%%H:%%%M:%%%S %%%Z"), ss: .current.sunset | strflocaltime("%%%H:%%%M:%%%S %%%Z"), pop1: .hourly[0].pop, pop2: .hourly[1].pop}]' >| ~/tmp/w
sed 's/"ct"/Current/; s/"fl"/Feels Like/; s/"hu"/Humidity/; s/"uv"/UV/; s/"ws"/Wind/; s/"wr"/Weather/; s/"sr"/Sunrise/; s/"ss"/Sunset/; s/"pop1"/Precip Probability 1 hr/; s/"pop2"/Precip 2 hr/' \
~/tmp/w
}
fi # Android
# Oracle Linux #{{{1
#----------------
if [[ -f /etc/os-release ]]; then
. /etc/os-release
if [[ "$ID" == "ol" ]]; then
export TZ="America/New_York"
if [ "${LOGNAME}" = 'oracle' ]; then
echo '.bashrc: setting ORACLE_HOME...'
export ORACLE_HOME=/u01/app/oracle/product/version/db_1/
fi
# OCI:
if [ "${LOGNAME}" = 'opc' ]; then
#echo '.bashrc: opc user detected'
#alias mailx='mailx -f /home/opc/mail'
export MAIL=/home/opc/mail
# Windows Terminal vim syntax bugfix
export TERM=screen-256color
if [[ "$VERSION_ID" == "8.10" ]]; then
alias vi=/usr/local/bin/vim
fi
fi
fi
fi
;; # end Linux
#-------------------
# NetBSD #{{{1
#-------------------
'netbsd')
echo '.bashrc: NetBSD detected'
# TODO this is only expecting sdf, add hostname filter
export EDITOR=/usr/pkg/bin/vim
# For mutt on sdf at least
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8
export MAILCHECK=5
export PATH=$HOME/bin:$PATH:/usr/pkg/bin
# TODO colors force lines to not wrap to new line
export PS1='${fg_darkgray}\j ${fg_whitebold}\u@${HOSTNAME}${fg_darkgray} \W/ \d \t ${normal} \n\$ '
# export PROMPT_COMMAND='echo -ne "\033]0;`stoppedjobs`${HOSTNAME:0:6}:${PWD}\007"'
export SURFRAW_text_browser=w3m
export WWW_HOME=http://www.google.com
export TERM=xterm-256color
export TZ=/usr/share/zoneinfo/US/Eastern
if [ $HOSTNAME = 'sdf' ] || [ $HOSTNAME = 'sverige' ]; then
alias crontab=mkcron
fi
alias jam='ps -aux | grep $USER'
alias la='\ls -la'
alias ls='\ls -F'
alias ll='\ls -Fl'
alias sha1sum='cksum -a sha1 '
alias ve="vi ~/.vimrc"
alias vi='/usr/pkg/bin/vim'
umask 077
# This should be in .bash_logout:
## Flush so that mail received during this login session is not counted
## at next login.
# mailstat $HOME/.procmail/log 1>/dev/null
#----------------
# Functions NetBSD #{{{2
#----------------
shopt -s cdspell checkhash checkwinsize cmdhist huponexit \
histappend cdable_vars
;; # end NetBSD
# Mainframe #{{{1
#-------------------
'OS/390')
echo '.bashrc: OS/390 detected'
export EDITOR=vim
export PATH=$HOME/bin:/IBMGNU/bin:/usr/local/bin:$PATH
# Mandatory for dtelnet
export TERM=xterm
# whoami returns OMVSKERN but $LOGNAME is bqh0
unalias ls
alias bc="bc -l" # allow floating point calcs
alias l='ls -F'
alias ls='ls -F'
alias la='ls -aF'
alias ll='ls -lF'
alias lt='ls -ltF | head -n20' # latest twenty
alias vi=vim
umask 022
;; # end OS/390
* ) #
###if [ -z $NONINTERACTIVE ]; then
echo "$HOME/.bashrc: Unknown OSTYPE. May need to edit .bashrc"
###fi
;;
esac # }}}1
# Security or project related additions: #{{{1
# if [ $HOSTNAME = 'SAS-01' ] || [ $HOSTNAME = 'SAS-02' ]; then
# export SASV9_OPTIONS='-validvarname=any'
# fi
if [ -e $HOME/.bashrc.local ]; then
echo ".bashrc: sourcing $HOME/.bashrc.local..."
source $HOME/.bashrc.local
fi
#