-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_bashrc
941 lines (862 loc) · 23.6 KB
/
_bashrc
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
# .bashrc
case $LD_PRELOAD in
?*)
# Set by replacebell -- we don't want this to stick around
unset LD_PRELOAD
;;
esac
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
case $(uname) in
SunOS)
export PATH=/usr/mysql/bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/local/sbin:/usr/gnu/bin
;;
esac
mypath=$HOME/.rbenv/bin:$HOME/node_modules/.bin:$HOME/bin:/usr/java/latest/bin:/opt/vagrant/bin:$PATH:/stat/local/bin
if [ -x /usr/local/bin/cknfs ]
then
echo -n "cknfs ... " >&2
checked_path=$(/usr/local/bin/cknfs -q -t 2 -su $mypath)
if [ -n "$checked_path" ]
then
export PATH="$checked_path"
echo done >&2
else
echo fail >&2
fi
else
export PATH=$mypath
fi
if type rbenv >/dev/null 2>&1
then
eval "$(rbenv init -)"
rubyver23=$(rbenv versions | tac | awk '$1 ~ /^2\.3\./ {print $1}')
fi
if [ -d $HOME/lib/perl/share/perl ]
then
export PERL5LIB=$(echo $HOME/lib/perl/share/perl/5.* | tr " " :)
fi
if [ -d /opt/python ]
then
export PYTHONPATH=/opt/python/lib/python2.7/site-packages
fi
if type podman >/dev/null 2>&1
then
export DOCKER=podman
fi
if type vault >/dev/null 2>&1
then
export VAULT_ADDR=https://vault.i.bitbit.net
fi
# If not running interactively, don't do anything more
######################################################
[ -z "$PS1" ] && return
# Does $- contain "i" for interactive? We remove i* and see that the
# value is unchanged.
[ ${-%i*} = $- ] && return
# TAB completion rules
declare -a hosts
if [ -e ~/.ssh/known_hosts ]; then
hosts=(`awk -F"[ ,]" '/^([0-9]+[.]|\[)/ { next } {print $1}' ~/.ssh/known_hosts`)
fi
if [ -e ~/.ssh/config ]; then
hosts=(${hosts[*]} `awk '/^Host [a-z0-9.-]+ *$/ { print $2 }' ~/.ssh/config`)
fi
complete -r
complete -W "${hosts[*]}" ssh ssh-keygen telnet nc ping ping6 host showmount mtr traceroute vlan cssh console
complete -W "${hosts[*]}" -o default scp rsync bacula-conf thruk
complete -C /usr/bin/vault vault
for comp in /usr/share/bash-completion/completions/pass /etc/bash_completion.d/password-store
do
if [ -e "$comp" ]
then
. "$comp"
break
fi
done
scp() {
local -a args=("$@")
local last_arg=$(( ${#args[@]} - 1))
case ${args[$(( last_arg - 1))]} in
*:*)
# okay, penultimate argument is a remote source, don't
# change target argument.
;;
*)
case ${args[$last_arg]} in
*:*|*/*)
# last argument is a remote source
;;
*)
echo "(fixing destination)" >&2
args[$last_arg]="${args[$last_arg]}:"
;;
esac
;;
esac
command scp ${args[@]}
}
if [ -e $HOME/.work-password-store ]
then
alias workpass='PASSWORD_STORE_GPG_OPTS="--trust-model always" PASSWORD_STORE_DIR=~/.work-password-store ${HOME}/.work-password-store/bin/pass'
. ${HOME}/.work-password-store/bin/workpass.bash-completion
fi
if [ "$BASH_VERSINFO"0 -ge 40 ]
then
shopt -s globstar
fi
_rl="`tput rmm`"
_titlebar='\e]0;${CHOOSEHOST+» }\u@\H ${OS_PROJECT_NAME+«${OS_PROJECT_NAME}»}\a'
_titlebar='\e]0;${CHOOSEHOST+» }\u@\H\a'
_status='\e[$(($??1:0))m'
_prompt=': [\u@\h \w];'
_reset='\[\e[0m\]'
case $TERM in
linux) PS1="\[${_status}\]${_prompt}${_reset} "
;;
xterm*|rxvt*)
# Store exit status in _S_ (if error, PIPESTATUS).
# Enclose it in {}, this makes it easy to remove "{0} ".
_func_PC='_PC_() { _S_="{${?/#[1-9]*/${PIPESTATUS[@]}}""} "; }'
eval $_func_PC
PROMPT_COMMAND=_PC_
trap '_PC_() { echo "New window size: ${COLUMNS}x${LINES}"; eval $_func_PC; } ' winch
_prompt=': ${_S_/#\{0\} /}[\u@\h \w];'
PS1="\[${_rl}${_titlebar}${_status}\]${_prompt}${_reset} "
;;
*) PS1="${_prompt} "
;;
esac
export VIMINIT=':set cp
set noai
set nosi'
if ! vi --version | fgrep -q -e '-syntax'
then
export VIMINIT="${VIMINIT}
syntax off"
fi
unalias vi la 2>/dev/null
# We don't want ^S
[ -t 0 ] && stty stop undef
if [ disabled = yes -a "$DISPLAY" != "" ]
then
# Find suitable locale for Evolution
unset LC_TIME
for loc in $(locale -a | grep -i 'en_.*utf')
do
# why did I want to do this?
# case $loc in
# en_US*) export LANG=$loc ;;
# esac
if [ "$LC_TIME" = "" ]
then
[ "$(LC_TIME=$loc date +%p)" = "" ] && export LC_TIME="$loc"
fi
done
fi
if [ "$XTERM_LANG" != "" ]
then
export LANG="$XTERM_LANG"
fi
if [ -n "SSH_CLIENT" ]
then
export MOSH_SERVER_NETWORK_TMOUT=604800
fi
export LC_COLLATE=C LC_NUMERIC=C
export EDITOR=vi
export PAGER=less
# rspec-puppet
if [ -d ~/git/git.i.bitbit.net/puppet-ms0/basemodules_common/modules/ ]
then
export MODULEPATH=design:modules:~/git/git.i.bitbit.net/puppet-ms0/basemodules_common/modules/
export FUTURE_PARSER=yes STRICT_VARIABLES=yes
fi
bN() {
declare ver="$1";
declare rubyver=2.1.10
declare -a cmd=(bundle)
shift;
case $ver in
3|4) rubyver="2.1.10" ;;
*) rubyver="${rubyver23-2.3.8}" ;;
esac
if [ ! -r .ruby-version ] || [ $(< .ruby-version) != $rubyver ]
then
rbenv local $rubyver
fi
if [ ! -r .bundle/config ]
then
env PUPPET_VERSION="~> $ver.0" PUPPET_GEM_VERSION="~> $ver.0" bundle install --path=$HOME/.cache/bundler/
fi
case $1 in
rake|rspec|gem) cmd=("${cmd[@]}" exec) ;;
esac
ourbase=~/git/git.i.bitbit.net/puppet-ms0/basemodules_common/modules
apibase=~/git/git.i.bitbit.net/puppet-ms4/api_common/modules
case $PWD in
*/api*)
export MODULEPATH=design:modules:$apibase:$ourbase
echo "Adding API base to MODULEPATH: $MODULEPATH"
;;
*)
export MODULEPATH=design:modules:$ourbase ;;
esac
env PUPPET_VERSION="~> $ver.0" PUPPET_GEM_VERSION="~> $ver.0" "${cmd[@]}" "$@"
}
b3() { bN 3 "$@"; }
b4() { bN 4 "$@"; }
b5() { bN 5 "$@"; }
b6() { bN 6 "$@"; }
b() {
(
if [ -r Gemfile.lock ]
then
version=$(awk '$1 == "puppet" { gsub("[(]|\\..*", "", $2); print $2; exit }' Gemfile.lock)
fi
bN ${version-3} "$@"
)
}
B() {
case $1 in [0-9]*) version=$1; shift;; *) version=3;; esac
chmod 1777 spec/fixtures/manifests spec/fixtures/modules
rm -f spec/fixtures/manifests/site.pp spec/fixtures/modules/${PWD##*/}
docker run -v $(pwd):/tmp/test:rw -w /tmp/test containers.i.bitbit.net/ci-images/puppet-test:$version "$@"
}
bgem() {
local gem="$1"; shift
local -a args
case $1 in
-v)
args=($@) ;;
[0-9]*)
args=(-v "$@") ;;
"")
: ;;
*)
echo "Usage: bgem gemname [version]" >&2;
return
;;
esac
b gem contents "$gem" ${args[*]} | grep -v /spec/
}
bfacter() {
local facterver=$(b exec facter --version | cut -d. -f-2)
bgem facterdb | fgrep /$facterver/
}
j() {
if [ $# -gt 0 ]
then
local expr="$1"
shift
jq "$@" ".[] | $expr"
else
jq ".[] | .certname"
fi
}
grep_options="--directories=skip --colour=auto"
alias grep="grep $grep_options"
alias egrep="egrep $grep_options"
alias fgrep="fgrep $grep_options"
export GREP_COLOR="01"
export LESS="-j4R"
unset LESSOPEN
less() {
# we only check the first non-option argument for the :linenum suffix
declare -a opts
while [ $# -gt 0 ]
do
case $1 in
[-+]*)
opts=( ${opts[@]} "$1" )
shift;
;;
*:*)
if [ ! -e "$1" ]
then
base=${1%:*}
num=${1##*:}
if [ -e "$base" ]
then
shift
command less -N -j0 +"$num" ${opts[@]} "$base" "$@"
return
fi
fi
break
;;
*)
break
;;
esac
done
command less ${opts[@]} "$@"
}
HISTTIMEFORMAT="%H:%M:%S "
HISTSIZE=50000
HISTFILESIZE=50000
# ikkje lagre kommandoar som startar med ":" (i praksis ":;") eller " " i historikk
HISTIGNORE="\:*: *"
HISTCONTROL=ignoredups
alias ls="ls -F"
alias hsot=host
alias mv="mv -i"
bind "set prefer-visible-bell Off"
bind '"\en": history-search-forward'
bind '"\ep": history-search-backward'
bind "set mark-modified-lines On"
bind "set revert-all-at-newline On"
bind 'Control-g: "git branch\n"'
host_colour() {
local host=$1 bg=${2-fdf6e3}
local sum=$(echo $host | sha256sum)
# We use 6 bits (0x3f) from each of the first three octets from
# the hash and remove this pseudo-random value from the default
# colour.
perl -e '@def = map { hex } "'$bg'" =~ /(..)(..)(..)/;
@rgb = map { hex($_) & 0x3f } "'${sum:0:6}'" =~ /(..)(..)(..)/;
printf("%02x%02x%02x\n",
$def[0]-$rgb[0], $def[1]-$rgb[1], $def[2]-$rgb[2]);'
}
ssh() {
for arg
do
case $arg in
-*) : ;;
*) likely_host="$arg"
break
;;
esac
done
printf '\e]0;%s\a' "$likely_host" >&2
case $TERM in
rxvt*|xterm*)
default_bg='fdf6e3'
printf '\e]11;#%s\a' $(host_colour $likely_host $default_bg)
;;
esac
env TERM=xterm ssh "$@"
ssh-reset
}
ssh-reset() {
[[ $default_bg ]] && printf '\e]11;#%s\a' $default_bg
}
# pdsh(1) default is rsh
export PDSH_RCMD_TYPE=ssh
percd() {
history -w
builtin cd "$@" && {
[ -d ~/.bash_history.d ] || mkdir -p ~/.bash_history.d
HISTFILE=$HOME/.bash_history.d/${PWD//\//_}
history -c
if [ -r $HISTFILE ]
then
history -r
fi
}
}
stderr() { echo "$@" >&2; }
nosvn() {
find . \( -type d \( -name .svn -o -name .git \) -prune \) -o \( "$@" \)
}
newest() {
if [ -z "$1" ]
then
nosvn -printf '%T+ %p\n' | sort -rn | head -1
else
find . \( -type d -name '.svn' -prune \) -o \
\( "$@" -printf '%T+ %p\n' \) | sort -rn | head -1
fi
}
set +f # so a reload of .bashrc fixes it
alias finn='set -f; do_finn'
do_finn() {
name="$1"; shift;
if echo "$name" | grep '^[a-zA-Z0-9_.-]*$' >/dev/null
then
name="*$name*"
fi
case $1 in
[a-zA-Z]*)
nosvn -name "$name" -print0 | xargs -0 "$@"
;;
*)
nosvn -name "$name" "$@" -print
;;
esac
set +f
}
forallf() {
nosvn -type f -print0 | xargs -0 "$@"
}
foralld() {
nosvn -type d -print0 | xargs -0 "$@"
}
hdr() {
nosvn -type f \( -name '*.h' -o -name '*.hh' \) -print0 | xargs -0 "$@"
}
src() {
nosvn -type f \( \
-name '*.[physicCl]' \
-o -name '*.p[lmyp]' \
-o -name '*.cc' \
-o -name '*.hh' \
-o -name '*.cpp' \
-o -name '*.rb' \
-o -name '*.erb' \
-o -name '*.cf' \
-o -name '*.cfg' \
-o -name '*.conf' \
\) -print0 | xargs -0 "$@"
}
edit_last() {
local prev_output=$(fc -s "$@")
if [[ ! "$prev_output" ]]
then
echo "No output from last command" >&2
return
fi
local IFS='
'
local files=($(echo "$prev_output" | sed s/:.*// | sort -u))
e "${files[@]}"
}
alias e!=edit_last
la() {
# base 4.3 is confused where to end $() with case inside.
for p do
files=`type -a "$p" | while read e
do
case $e in
"$p is a"*)
echo "$e"
;;
"$p ()")
# function definition, ignore
;;
"$p is "*)
echo "$e" | cut -d' ' -f3-
;;
esac
done` 2>&1
[ "$files" ] && ls -lL $files
done
}
File() {
for file
do
[ -L "$file" ] && file=$(readlink -f "$file")
file "$file"
done
}
lw() {
local strings p full
case $# in
0) stderr "Usage: lw [-s] <program> [<program> ...]"
stderr "View the listed programs. With -s, run strings."
return
;;
*) strings=false;
case $1 in
-s) strings=true; shift;;
esac
for p do
full=`type -path "$p"`
$strings && ( strings "$full" | $PAGER ) || $PAGER "$full"
done
;;
esac
}
mysudo() {
HOME=/root pfexec bash
}
myget() {
local url
for url; do wget -r -nd -l 1 -A "${url##*/}" "${url%/*}"; done
}
sleep-until() {
local target=$(date -d "$*" +%s.%N)
sleep $(echo $target - $(date -d "now" +%s.%N) | bc)
}
case `uname -n`:$COLUMNS in
login.redpill-linpro.com:64)
screen -Urx
;;
*.ms.redpill-linpro.com:*)
if [ "$CHOOSEHOST" ]
then
bind 'set show-all-if-ambiguous On'
bind 'set page-completions Off'
bind 'C-w: menu-complete'
complete -W ssh -E
unset LC_TIME
command_not_found_handle() {
host=$1; shift
for m in ${hosts[*]}
do
case $m in
$host*|$host)
case $m/$host in
*-mgmt*/*-mg*)
host=$m
break
;;
*-mgmt*/*)
: # ignore mgmt address unless specified
;;
*)
host=$m
break
;;
esac
;;
esac
done
for m in ${hosts[*]}
do
case $m in
$host.*|$host)
host=$m
break
;;
esac
done
case $1 in
cl|clean)
ssh-keygen -R $host
;;
*)
echo "logging in to $host ... "
ssh $host "$@"
;;
esac
}
fi
;;
esac
stockprice() {
local date="$1"
local ticker="$2"
# charmap=$(locale -c charmap | tail -1)
curl -s "http://hopey.netfonds.no/paperhistory.php?paper=$ticker&csv_format=txt"| egrep "^(quote|$date)" | iconv -f latin1 -t utf8 | sed "s/ Børs//"
}
function repeat() {
declare -i num=$1; shift
while [ $num -gt 0 ]; do
"$@" || return
num=num-1
done
}
function up () {
case $# in
0) cd ..
;;
1) savepwd=$PWD;
repeat $1 cd ..;
OLDPWD=$savepwd
;;
esac
}
# Usage: g [print] <substring> [<restriction>]
# "g _net" will do cd ~/git/git.i.bitbit.net/puppet-ms0/bitbit_net
# "g _net ans" will do cd ~/git/git.i.bitbit.net/ansible/bitbit_net
#
# With "print", list all possible matches. Without "print", the
# first match will be used as new current directory.
#
g() {
local cd=cd
if [ $# -gt 1 -a "$1" = print ]
then
cd=echo; shift
fi
case $1 in
-|"") cd - ;;
/*) cd "$1" ;;
p|pu) $cd ~/svn/puppet ;;
pup|pupp|puppet) $cd ~/git/git.i.bitbit.net/puppet-mod/puppet ;;
ici) $cd ~/git/git.i.bitbit.net/icinga/config ;;
meta) $cd ~/git/git.i.bitbit.net/mirror/meta ;;
*)
for p in "git/git.i.bitbit.net/ops/$1/puppet" \
"git/git.i.bitbit.net/ops/*$1/puppet" \
"git/git.i.bitbit.net/ops/*$1*" \
"git/git.i.bitbit.net/ops/*/$1*" \
"git/git.i.bitbit.net/*/$1" \
"git/git.i.bitbit.net/*/$1*" \
"git/gitlab.redpill-linpro.com/$1*" \
"git/git.i.bitbit.net/puppet*/*$1*" \
"git/git.i.bitbit.net/ansible/*$1*" \
"git/git.i.bitbit.net/ansible/*/*$1*" \
"git/git.i.bitbit.net/*/*$1*" \
"git/gitlab.redpill-linpro.com/*/*$1*" \
"svn/$1*" \
"git/github.com/*/$1*" \
"git/github.com/*/*$1*" \
"git/*/*$1*"
do
for m in $HOME/$p/
do
if [ -d "$m" ] # could be unexpanded with "*" intact
then
case "$m" in
$HOME/*"$2"*)
if [ $cd = cd ]
then
cd "$m" && return
else
$cd "$m" | egrep "($1|$2)"
fi
;;
esac
fi
done
done
;;
esac
}
# Jump to webpage for current git repo
# Usage: gw [--print] [FILE] [REMOTE]
# Default remote is "origin"
gw() {
local file xdg_open=${XDG_OPEN-xdg-open}
if [ "$1" = "--print" ]
then
xdg_open=echo; shift
fi
if [ "$1" -a -e "$1" ]
then
file="$1"; shift
fi
local origin="${1-origin}"
local giturl=$(git remote get-url $origin) || return
local url=$(echo "$giturl" | sed -e 's|^[a-z]\+@\([^:]\+\):|https://\1/|' -e 's|\.git$||')
if [ "$file" ]
then
local branch=$(git branch --show-current)
url="${url}/-/blob/${branch}/${file}"
fi
${xdg_open} "$url"
}
gmv() {
local from="$1" to="$2"
local base=$HOME/git/git.i.bitbit.net
case $to in
"") to="$1"
from=$(pwd | sed "s,$base/,,")
;;
*/*) : ;;
*) to="$to/${from##*/}" ;;
esac
base=$HOME/git/git.i.bitbit.net
if [ ! -d "$base/$from" ]
then
echo No such repo
return
fi
[email protected]:$to.git
echo Updating $from to $new_remote
if (cd $base && mkdir -p $(dirname $to) && mv "$from" "$to")
then
cd $base/$to
git remote set-url origin $new_remote
fi
}
gset-upstream() {
git branch --set-upstream-to=${1-origin}/$(git symbolic-ref --short HEAD)
}
_gclone() {
local server="$1"
shift
declare -a args=("$@")
# get last argument, remove trailing / if present
local proj="${args[${#args[@]} - 1]%/}"
# remove last argument
unset "args[${#args[@]} - 1]"
url="git@${server}:${proj}.git"
dir=$(dirname ~/git/$server/$proj)
mkdir -p $dir
cd $dir &&
git clone "${args[@]}" $url &&
cd ~/git/$server/$proj
}
gfork() {
local user=${1-$USER}
local fork=$(git remote get-url origin | sed "s,:[^/]*,:$user,")
git remote add $user $fork
}
gclone() {
_gclone git.i.bitbit.net "$@"
}
grlclone() {
_gclone gitlab.redpill-linpro.com "$@"
}
ghclone() {
_gclone github.com "$@"
}
glclone() {
_gclone gitlab.com "$@"
}
gc-() {
git checkout -
}
gitmr() {
local branch automerge merge current_main
read -p "Name of feature branch: " branch
if [[ -z $branch ]]
then
echo "aborting."
return
fi
read -p "Auto-merge? [no] " automerge
case $automerge in
y|yes)
merge="-o merge_request.merge_when_pipeline_succeeds"
;;
esac
current_main=$(git branch --show-current)
git push -o merge_request.create -o merge_request.target="${current_main}" $merge origin "${current_main}":"${branch}"
}
# Remove local remote refs which no longer exist
git-cleanup-refs() {
git remote prune ${1-origin};
}
# Remove remote branches if they have been merged into current branch
# For safety, only look at "feature/xxx" branches
git-cleanup-merged-feature-branches() {
local rem=${1-origin}
local branches=$(git branch -r --merged | sed -n "s,$rem/feature,feature,p")
if [[ $branches ]]
then
printf "%s\nPress enter to delete, ^C to abort: " "$branches"
read x
git push origin --delete $branches
else
echo "No unmerged branches on '$rem'"
fi
}
upd() {
(cd $HOME/svn
for m in puppet
do
(cd $m 2>/dev/null && svn up)
done
cd $HOME/git/git.i.bitbit.net
for m in */*
do
(cd $m && git pull --ff-only)
done
)
}
h() {
for m in ${hosts[*]}
do
case $m in
*$1*)
echo $m;
;;
esac
done
}
# output from portloginshow
function fe() {
case $1 in
*:*:*)
wwn="$1"
;;
*)
wwn="$2"
;;
esac
grep -h -i -B 4 $wwn $HOME/tmp/*-zone | grep 'Zone:'
}
function horse() {
local lang="${1-en}" words=${2-4}
for i in a b c d e
do
echo $(aspell -d $lang dump master | egrep -v '.{11}' | tr -d \" | shuf -n $words)
done
}
alias horse-en="horse en"
alias cwdiff="wdiff -n -w $'\033[30;41m' -x $'\033[0m' -y $'\033[30;42m' -z $'\033[0m'"
alias qr="xclip -o selection clipboard | qrencode --size 10 -o - | feh -x --title QR -g +200+200 -"
alias trunc='cut -c-${COLUMNS-80}'
alias mtr='env TERM=vt220 mtr'
osinit() {
case $1 in
--clear)
unset $(set | grep ^OS_ | cut -d= -f1)
shift
[ $# = 0 ] && return
;;
'')
echo "Current project is '$OS_PROJECT_NAME'"
return
;;
esac
local proj="$1"
export OS_COMPUTE_API_VERSION=2.53 # To access all Pike features
if [ "$OS_PROJECT_NAME" = "" -o "$OS_PROJECT_NAME" != "$proj" ]
then
if [ -r $HOME/.config/openstack/$proj-openrc.sh ]
then
. $HOME/.config/openstack/$proj-openrc.sh
else
echo "No openrc-file for '$proj'" >&2
fi
fi
}
complete -W "$(cd $HOME/.config/openstack; echo *-openrc.sh | sed s/-openrc.sh//g)" osinit
axfr-2a02() {
dig axfr 0.c.0.0.2.0.a.2.ip6.arpa. @ns-foo.i.bitbit.net |
perl -pe 's/(\S+)\.ip6\.arpa\./reverse($1)/e' | grep ^2 | sort
}
axfr-10() {
dig axfr 10.in-addr.arpa. @ns-foo.i.bitbit.net |
perl -pe 's/(\S+)\.in-addr.arpa\./join(".", reverse(split(m{[.]}, $1))) . "\t"/e' | grep ^1 | sort
}
axfr() {
case $1 in
[1-9]*.[1-9]*)
dom=$(perl -e 'print join(".", reverse(split(/\./, $ARGV[0])), "in-addr.arpa")' $1)
;;
*.*) dom="$1" ;;
*) dom="$1.bitbit.net" ;;
esac
dig axfr $dom @ns-foo.i.bitbit.net
}
whois.no() {
ssh login-osl2.i.bitbit.net whois -h registrarwhois.norid.no "$@";
}
mdview() {
pandoc -t html -o /dev/stdout "$1" | ifne w3m -T text/html -o display_link=true -o confirm_qq=false
}
nsupd() {
nsupdate -k$HOME/.config/dns/$USER.user.private "$@"
}
lc() {
tr '[:upper:]' '[:lower:]'
}
uc() {
tr '[:lower:]' '[:upper:]'
}
tomquiz() {
local num="$1"
local dir=$HOME/Documents/quiz/tom
local count=$(ls -1 $dir/$num.*.xlsx 2>/dev/null | wc -l)
if [ "$count" -ne 1 ]; then echo "$count matching PDF files"; return; fi
xdg-open $dir/$num.*.pdf &
xdg-open $dir/$num.*.xlsx &
}
# For a limited time only - until all my shells has transitioned from
# r alias to r function. -kjetilho 2022-10-22
if alias -p | grep -q 'alias r='
then
unalias r
fi
r() {
ssh-reset
. ~/.bashrc
}