-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
1789 lines (1538 loc) · 42.4 KB
/
.functions
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
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/zsh
source $HOME/.debug_state
isDebug && echo "1) \${SHELL_ALIAS_SOURCED} = ${SHELL_ALIAS_SOURCED}"
([[ -z ${SHELL_ALIAS_SOURCED} ]] || ! ${SHELL_ALIAS_SOURCED}) && export SHELL_ALIAS_SOURCED=true || return 222
isDebug && echo "2) \${SHELL_ALIAS_SOURCED} = ${SHELL_ALIAS_SOURCED}"
isDebug && echo "Script name ${0}" 2> /dev/null
log-write "com.googlecode.iterm2" "${0} :"
log-write "com.googlecode.iterm2" "\$SHELL_FUNCTIONS = ${SHELL_FUNCTIONS}"
log-write "com.googlecode.iterm2" "\$BASHFUNCTIONS = ${BASHFUNCTIONS}"
log-write "com.googlecode.iterm2" "\$SHELLFUNCTIONS = ${SHELLFUNCTIONS}"
log-write "com.googlecode.iterm2" "alias ekko $(alias ekko)"
BASHFUNCTIONS=${0}
SHELLFUNCTIONS=${0}
BINFUNCTIONS=$SHELL_FUNCTIONS
SCRIPTNAME="${0}"
export CLICOLOR=1
[[ -z "$ALIASES_SET" ]] && [[ -r ~/.shell_aliases ]] && source ~/.shell_aliases
#[[ -z "${SHELL_VARS}" ]] && [[ -r ~/.shell_vars ]] && source ~/.shell_vars
source ~/.shell_vars
source ~/.shell_vars_regex
#source ${SHELL_VARS_REGEX}
source ${BIN:-${HOME}/bin}/.functions-broot.sh
scpup2 ()
{
if [ ! ${1} ]; then
echo "Usage: scpup2 sourcefile destinationfile"
return 1
elif [ ! ${2} ]; then
DEST=$(basename ${1})
else
DEST=${2}
fi
echo [email protected]:~/$DEST
return $?
scp -r ${1} [email protected]:~/$DEST
}
# FileSearch
fp() {
mkdir -p "/var/log/find"
SP='./'
if isDebug; then
echo "Parameters: ${#} arguments";
fi
# PARAMCOUNT=$(($#+1))
PARAMCOUNT=$#
# PARAMCOUNT=$(($#-1))
if [ -n ${2} ]; then
SP=$(abspath ${2})
PARAMCOUNT=3
fi
if [[ $# -gt 2 ]]; then
_OPTION="-name"
else
_OPTION="-iname"
fi
if isDebug && [ -n "$COLOR_Cyan" ] ; then
printf "${COLOR_LightGreen}find ${COLOR_Yellow}$SP ${COLOR_Cyan}$_OPTION ${COLOR_LightCyan}\"*${COLOR_LightGreen}${1}${COLOR_LightCyan}*\"${COLOR_NC} ${@:$PARAMCOUNT}"
elif isDebug; then
echo "find $SP $_OPTION \"*${1}*\" ${@:$PARAMCOUNT}"
fi
RESULT=$(find $SP $_OPTION "*${1}*" | tee -a "/var/log/find/${1}.log")
printf "${COLOR_Cyan}$RESULT"
}
param() {
PC=2
echo "count $#"
echo "\${0} ${0}"
echo "0 ${@:0}"
echo "1 ${@:1}"
echo "2 ${@:2}"
echo "3 ${@:3}"
echo "$PC ${@:PC}"
echo "${1}" ${@:2} -R .
}
#r_() {
## grep "${1}" ${@:2} -R .
# PARAM=${1}
# shift
# r_it() {
# grep -irl $PARAM "$@"
# }
#
# for fname in "$@";
# do
# r_it "$fname"
# done
#}
opex() {
xdg-open ${1} &
}
alldoc() {
fmp_helperx() {
eval "$@";
}
for fname in "$@"; do
fmp_helperx "$fname";
done
fmp_helper() {
echo "$@";
}
}
fmp () {
fmp2() {
nautilus "$@";
};
for fname in "$@";
do
fmp2 "$fname";
done;
}
chparam () {
chparam2() {
echo "$@";
};
for fname in "$@";
do
chparam2 "$fname";
done;
}
chparam_a () {
echo "$@";
echo ${1}
# shift
# echo "1: ${@:1}";
# echo "2: ${@:2}";
echo "####################"
chparam_a2() {
echo "2: $(abspath $@)";
};
# echo "for fname in `ls \"$@\"`";
for fname in `ls "$@"`;
do
echo "$fname"
chparam_a2 "$fname";
echo "##########"
done;
}
checkfile() {
if [ $# -eq 2 ];then
COUNT=${1}
else
COUNT=45
fi
checkfile_it() {
while true;
do
clear;
tail -$COUNT "$@";
sleep 1;
done
}
if [ $# -eq 2 ];then
shift
fi
for fname in "$@"
do
checkfile_it "$fname"
done
}
sln() {
ln -s `pwd`/${1} ${2}
}
lns() {
OPT=''
if [ -n ${3} ]; then
OPT=${3}
fi
#ln -s$OPT `pwd`/${1} ${2};
ln -s$OPT "$PWD/${1}" ${2};
}
##############################
## DEPRECATED ##
## see lnsa() ##
##############################
# lna() {
# PARAM1="${1}"
# PARAM2="${2}"
#
# lna_it() {
# for file in `ls ${1}`;
# do
# ln -s ${1}/$file ${2}/$file;
# done
# }
#
# lna_it "$PARAM1" "$PARAM2"
#}
#############################
show_() {
#cat ${UNUTMALIST}/*${1}*;
tail -n +1 ${UNUTMALIST}/**/*${1}*;
}
show2() {
#cat ${UNUTMALIST}/*${1}*;
tail -n 1 ${UNUTMALIST}/*${1}*;
}
#show () {
# echo foo > "${UNUTMALIST}/foo${1}.tmp"
# tail -n +1 ${UNUTMALIST}/**/*${1}* | sed '/foo/d'
# rm -f "${UNUTMALIST}/foo${1}.tmp"
#}
cheat() {
open http://borkware.com/quickies/one?topic=${1};
}
gr2() {
PARAM=${1}
r2_it() {
grep -irl $PARAM "$@"
}
shift
callfunction r2_it "$@"
}
callfunction() {
${1} ${2}
}
testfunc2 ()
{
echo "$# parameters";
echo Using '$*';
for p in $*;
do
echo "[$p]";
done;
echo Using '"$*"';
for p in "$*";
do
echo "[$p]";
done;
echo Using '$@';
for p in $@;
do
echo "[$p]";
done;
echo Using '"$@"';
for p in "$@";
do
echo "[$p]";
done
}
opentimedoc() {
#echo "PID $$"
#echo "\${1}.length=${#1}"
#[ ${#1} -ne 0 ] && [ -r ${1} ]; echo $?
export STANDARD_FOLDER=~/Documents/Tätigkeitsnachweis
# getting the last edited excel sheet in the folder
if [ ${#1} -ne 0 ] && [ -r ${1} ]; then
CURRENT_PATH=${1};
elif [ "${1}" == "-h" ]; then
echo "usage: ${0} [<path to folder containing excel sheets>]"
echo "Help: finds the last edited excel sheet in the folder"
echo " if no folder is given, then \"$STANDARD_FOLDER\" is used"
return 0
else
CURRENT_PATH=$STANDARD_FOLDER
fi
CURRENT_DOC=$(ls -td $CURRENT_PATH/*.xls* 2> /dev/null | head -n 1)
# check if there's found at least one
NUM=$(ls $CURRENT_PATH/*.xls* 2> /dev/null | wc -l)
if [ $NUM -eq 0 ]; then
#if [ ! -f $CURRENT_PATH/*.xls* ]; then
echo "No Excel Sheet found"
echo "usage: ${0} [<path to folder containing excel sheet>]"
echo
return 1
fi
# when using only the folder without any wildcard expression: CURRENT_DOC=$(ls -td $CURRENT_PATH | head -n 1)
# PATH2DOC=$CURRENT_PATH/$CURRENT_DOC
# open sheet
PATH2DOC=$CURRENT_DOC
open /Applications/Microsoft\ Excel.app $PATH2DOC
}
manx() {
#echo $*
PATH2PS=$HOME/tmp/man2type/${1}.ps
mkdir -p $(dirname ${PATH2PS})
/usr/bin/man -t ${1} > "${PATH2PS}"
if [ -s "${PATH2PS}" ]; then
open "${PATH2PS}"
fi
}
man2type() {
OUTPUT_TYPE=ps
[[ -n "${2}" ]] && OUTPUT_TYPE="${2}"
CURREN_MAN_PATH=$(man-path ${1})
groff -T${OUTPUT_TYPE} -I $(dirname ${CURREN_MAN_PATH}) -mandoc -c $(filename ${CURREN_MAN_PATH}) > ${1}.${OUTPUT_TYPE}
original cp -f ${1}.${OUTPUT_TYPE} $HOME/tmp/man2type/
}
#giturlp() {
# PATH2REPO='.'
# if [ $# -gt 0 ]; then
# PATH2REPO="$@"
# fi
#
# for folder in ${PATH2REPO}
# do
# cat ${folder}/.git/config | grep -i url | cut -d'=' -f 2
# done
#}
androiddoc () {
open "http://android-docs.local/${1}";
}
# see $BIN/timestamp
# timestamp() { date +"%s"; }
ymd() { date "+%Y%m%d"; }
# Xcode-Project: execute from the folder with the Assests.xxasset/ folder
extractImages() {
cp *.imageset/*.${1} ${2};
}
# NixOS
# https://stackoverflow.com/questions/1378274/in-a-bash-script-how-can-i-exit-the-entire-script-if-a-certain-condition-occurs
yell() { echo "${0}: $*" >&2; }
die() { yell "$*"; exit 111; }
trying() { "$@" || ([ ${0} == "-bash" ] || dying "cannot $*") }
dying() {
echo "cannot $*";
sleep 1;
die "$*"
}
function try()
{
[[ $- = *e* ]]; SAVED_OPT_E=$?
set +e
}
function throw()
{
exit ${1}
}
function catch()
{
export ex_code=$?
(( $SAVED_OPT_E )) && set +e
return $ex_code
}
function throwErrors()
{
set -e
}
function ignoreErrors()
{
set +e
}
activate_xcode_commands() {
PATH=/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
}
reverse() {
tail -r -n $(cat "${1}" | wc -l) "${1}"
}
hexcount() {
for i in {0..15};do
if [ $i -eq 10 ]; then
i=A;
elif [ $i -eq 11 ]; then
i=B;
elif [ $i -eq 12 ]; then
i=C;
elif [ $i -eq 13 ]; then
i=D;
elif [ $i -eq 14 ]; then
i=E;
elif [ $i -eq 15 ]; then
i=F;
fi;
echo "0x$i";
done
}
realpathf() {
/usr/bin/python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}";
}
if [ -f .urlencode ]; then
. .urlencode
fi
inform() {
echo -e "\\033[1;36m[INFO]\\033[0m $*";
}
warn() {
echo -e "\\033[1;33m[WARNING]\\033[0m $*";
}
fatal() {
echo -e "\\033[1;31m[FATAL]\\033[0m $*";
echo "shell is about to get closed."
echo "Exiting in 3 seconds"
echo "CTRL-C to interrupt exiting"
sleep 3;
#echo "boom...exit";
exit 1 ;
}
#isNumber() {
# #re='^[0-9]+$'
# #return [[ ${1} =~ $re ]]
# if ! [[ ${1} =~ $REGEX_IS_NUMERIC ]] ; then
# return 1
# else
# return 0
# fi
# }
# isNumeric () {
# #if [ "${1}" -le 0 ] 2> /dev/null || [ "${1}" -gt 0 ] 2> /dev/null;then
# if [ "${1}" -eq "${1}" ] 2> /dev/null; then
# return 0
# else
# return 1
# fi
# }
# isNaN () {
# if [ "${1}" -le 0 ] 2> /dev/null || [ "${1}" -gt 0 ] 2> /dev/null;then
# return 1
# else
# return 0
# fi
# }
exx () {
eval "export ${1}=${2}"
}
lsns () {
[ -n "${1}" ] && SP="${1}" || SP="."
[ -n "${2}" ] && EXT="${2}" || EXT=".*"
find "$SP" -maxdepth 1 ! -type l | grep -e "$EXT$"
}
#first () {
# LINECOUNT=5
# WHERE=$PWD
# H=''
#
# if [ -n "${1}" ]; then
# PARAM1="${1}";
# startsWithDash $PARAM1 && H=$PARAM1[2] || LINECOUNT=$PARAM1
# #LINECOUNT=${1}
# fi
#
# if [ -n "${2}" ]; then
# PARAM2="${2}";
# startsWithDash $PARAM2 && H=$PARAM2[2] || WHERE=$PARAM2
# #WHERE="${2}"
# fi
#
# if [ -n "${2}" ]; then
# PARAM3="${3}";
# startsWithDash $PARAM3 && H=$PARAM3[2] || H="h"
# fi
#
# if isDebugLocal
# then
# echo $LINECOUNT
# echo $WHERE
# fi
#
# [[ -L $WHERE ]] &&
# ! endsWith $WHERE '/' &&
# WHERE="${WHERE}/"
#
# isDebugLocal && { echo "\$WHERE=${WHERE}"; echo "\$LINECOUNT=${LINECOUNT}"; }
# CMD="ls -l${H}FAGct \"$WHERE\" | head -n $(($LINECOUNT+1))"
# isDebugLocal && echo ${CMD}
#
# eval ${CMD}
#
# #$(echo "${CMD[@]}")
#}
ffirst() {
[ -n "${2}" ] && H="h" || H=''
OPTIONS="-l${H}FAiGctd"
ls $OPTIONS * | head -n "${1}"
}
last() {
LINECOUNT=5
WHERE=$PWD
if [ -n "${1}" ]; then
LINECOUNT=${1}
fi
if [ -n "${2}" ]; then
WHERE="${2}"
fi
if isDebug; then
echo $LINECOUNT
echo $WHERE
fi
[ -n "${3}" ] && H="h" || H=''
ls -l${H}FAGct "$WHERE" | tail -n "$LINECOUNT"
#ls -lhFaGtd * | tail -n "${1}"
}
members () {
dscl . -list /Users | while read user; do
printf "$user ";
dsmemberutil checkmembership -U "$user" -G "$*";
done | grep "is a member" | cut -d " " -f 1;
}
FileOrDirectory2 () {
for i in "$@"
do
[ -d "$i" ] && echo "$i is directory" || echo "$i is file"
done
# for i in "${@}/*"
# do
# [ -d "$i" ] && echo "$i is directory" || echo "$i is file"
# done
}
#for f in $(ls); do echo "bumm $f"; done
FileOrDirectory () {
for i in $(ls $@)
do
[ -d "$i" ] && echo "$i is directory" || echo "$i is file"
done
}
# see $BIN/isFile -> better 4 performance
#isFile () {
# if [ -d "${1}" ]
# then
# return 1
# else
# return 0
# fi
#}
isDirectory () {
if [ -d "${1}" ]
then
return 0
else
return 1
fi
}
isDir () {
[[ -d "${1}" ]]
return $?
}
dckrh () {
COMMAND="${1}"
docker $COMMAND --help
}
listarray () {
# listarray "$ARRAY" ; Don't forget the double quotes like in the sample
pARRAY="${1}";
IFS=$'\n';
echo "${pARRAY[@]}"
}
listarray2 () {
pARRAY="${1}";
IFS=$'\n';
echo "${pARRAY[*]}"
}
gituser () {
PATH2REPO='.'
if [ $# -eq 1 ]
then
PATH2REPO="$@"
fi
cat $PATH2REPO/.git/config | grep -i email | cut -d'=' -f 2
}
addPath2Places() {
echo "${1}" >> /Users/sedatkilinc/__Places/paths.txt
}
iterm2_print_user_vars() {
iterm2_set_user_var "gitBranch" "$(git branch 2> /dev/null | grep \* | cut -c3-)"
}
savelink() {
TARGET='';
if [ -n ${2} ]; then
TARGET="${2}";
mkdirlinks $(dirname $TARGET);
fi
createlink "${1}" ~/Desktop/LINKS/$TARGET;
}
savelink2() {
TARGET="$HOME/Desktop/LINKS/";
if [ -n "${2}" ]; then
TARGET="$TARGET/${2}"
echo $TARGET;
if ! [ -d " $TARGET" ]; then
mkdir $(dirname $TARGET);
fi
fi
echo "$TARGET"
createlink "${1}" "$TARGET";
}
countchar() { echo "${1}" | wc -c; }
aliasesStartingWith() { LETTER="${1}"; alias | grep -e "^$LETTER"; }
mkdirlinks () {
mkdir "$LINKS/${1}"
}
func_tmpdirr ()
{
echo "run"
: ${TMPDIR=/Users/sedatkilinc/tmp}
{
tmp=$TMPDIR
}
}
_debug () {
STATE="off"
if [ "$DEBUG" = $TRUE ]
then
STATE="on"
fi
echo "DEBUG is $STATE" > /dev/stdin
}
debug () {
echo -n "DEBUGGING is "
if isDebug;
then
echo "on" > /dev/stdin
else
echo "off" > /dev/stdin
fi
}
# absolute value
abs() {
echo "${1}" | tr -d -
}
# negating command exit status
# successfully executed command exits with 0 an failed one with 1
# so here, the negating is not mathematically but in the sense of obtaining the opposite
# possible that the YAGNI principle will kick my ass
_negate() {
echo $(( (${1} - 1) * -1 ))
}
negate () {
echo $(( ${1} * -1 ))
}
_isTrue() {
if [ "${1}" = $TRUE ]; then
return 0
else
return 1
fi
#[ ${1} = 1 ]
#RESULT=$(_negate $?)
#echo "Param ${1}. Result $RESULT"
}
#isDebug() {
# DEBUG=$(cat $DEBUG_STATE_FILE)
# if [ "$DEBUG" -eq $TRUE ] 2> /dev/null || [ "$DEBUG" = $TRUE ]; then
# return 0
# else
# return 1
# fi
#}
setDebug() {
# NEWSTATE=$(lowercase ${1})
export DEBUG=$TRUE
}
unsetDebug() {
# NEWSTATE=$(lowercase ${1})
export DEBUG=$FALSE
}
setProd() {
# NEWSTATE=$(lowercase ${1})
DEBUG=$FALSE
}
unsetProd() {
# NEWSTATE=$(lowercase ${1})
DEBUG=$TRUE
}
## functions converted to scripts in $HOME/bin folder
#lowercase() { echo "${1}" | tr '[:upper:]' '[:lower:]'; }
#uppercase() { echo "${1}" | tr '[:lower:]' '[:upper:]'; }
listGBElements() {
DEPTH=1
if [ $# -gt 1 ];
then
DEPTH=${2}
fi
du -h -d $DEPTH "${1}" | grep '[0-9]G\>'
}
listGBElements2() {
isDebug && echo \$#\ \=\ $#;
echo "\${0} = ${0}, \${1} = ${1}, \${2} = ${2}, \${3} = ${3}, \${4} = ${4}, \${5} = ${5}, \${6} = ${6}"
while [[ $# -gt 0 ]];# && [[ "${1}" == "--"* ]];
do
OPT=${1}
shift;
echo $OPT
done
}
webextrun() {
BROWSER=/Applications/Firefox.app
if [ -n "${1}" ]; then
BROWSER="${1}"
fi
web-ext run --firefox="$BROWSER/Contents/MacOS/firefox-bin"
}
mans2add() {
echo "man ${1}" >> $mans2read;
}
searchFolderForGitRepoX() { for i in $(ls -1 "${1}"); do [ -e "$i/.git" ] && echo "$i is a repo" && giturlp $i || echo "$i is a NOT repo"; done }
searchFolderForGitRepo() {
for i in $(ls -1 "${1}");
do
[ -e "$i/.git" ] &&
echo "$i is a repo" &&
giturlp "$i" ||
echo "$i is a NOT repo";
done
}
searchreplace() {
SOURCETEXT="${1}"
DELIMITER="${2}"
REPLACER=$([ -n "${3}" ] && $(echo "${3}") || echo ";")
echo "${1}" | perl -pe "s/${2}{1,}/$REPLACER/g"
}
#addalias () {
# if [[ $# -eq 0 ]]; then
# echo "Usage: $(basename "${0}") alias command"
# return 1
# fi
# #ALIASESFILE=$HOME/.bash_aliases
# WC_ORIG=$(cat ${SHELL_ALIASES} | wc -l)
# TMPFOLDER=$HOME/tmp/.bashstuff
# mkdir -p $TMPFOLDER
# TMPFILE=$TMPFOLDER/shell_aliases.prev
# original cp -f ${SHELL_ALIASES} ${TMPFILE}
#
# echo "alias ${1}='${2}'" >> ${SHELL_ALIASES}
#
# WC_NEW=$(cat ${SHELL_ALIASES} | wc -l)
# if [[ $WC_NEW -lt $WC_ORIG ]]; then
# echo "Error: New aliases-file didn't get extended"
# echo "Number of lines of previous aliases-file $WC_ORIG"
# echo "BUT number of lines of newly extended aliases-file $([[ $WC_NEW -eq $WC_ORIG ]] && echo "STILL" || echo "ONLY") $WC_NEW"
# echo "Backing up new aliases-file ${SHELL_ALIASES} to ${TMPFILE}.backup\! for further analysis."
# \cp -f ${SHELL_ALIASES} "${TMPFILE}.backup\!"
# [[ $? -eq 0 ]] && echo "Backup Successful" || echo "BackUp failed! Check path, destination directory for permissions or even existence"
# echo "Restoring previous aliases-file..."
# \cp -f ${TMPFILE} ${SHELL_ALIASES}
# [[ $? -eq 0 ]] && echo "...previous aliases-file ${TMPFILE} got restored to ${SHELL_ALIASES
#}
useOfTripple_Chevrons_LeftArrows() {
CMD='ccat < $(echo $PWD)';
echo "Executing $CMD";
eval "$CMD"
CMD='ccat << $(echo $PWD)';
echo "Executing $CMD";
eval "$CMD"
CMD='ccat <<< $(echo $PWD)';
echo "Executing $CMD";
ccat <<< $(echo $PWD);
}
find_aliasi_by_whole_word() {
CMD="alias | grep -i \\\'\\\b${1}\\\b\\\'"
echo $CMD
CMD="alias | grep -i '\b${1}\b'"
echo "$CMD"
$(echo $CMD)
}
strip_protocol () {
echo ${$(echo ${1} | cut -d ":" -f2)/\/\//}
}
string_contains() {
usage "${0}" "$#" 2 '<HAYSSTACK> <NEEDLE>' "checks if haystack contains needle" || return $?
if [[ ${1} == *"${2}"* ]] || [[ ${2} == *"${1}"* ]]; then
return 0;
else
return 1;
fi
}
string_contains_() {
#usage "${0}" "$#" 2 '<HAYSSTACK> <NEEDLE>' "checks if haystack contains needle" || return $?
if [[ ${1} == *"${2}"* ]] || [[ ${2} == *"${1}"* ]]; then
return 0;
else
return 1;
fi
}
get_subtitle_all () {
pVIDEO="${1}"
pFORMATS="${3}"
[[ -z $pFORMATS ]] && sub_formats=('vtt' 'srv1' 'srv2' 'srv3' 'ttml' ) || sub_formats=( "${pFORMATS[@]}" );
[[ -n ${2} ]] && LANG=${2} || LANG="de"
string_contains $pVIDEO "youtube" && URL="$pVIDEO" || URL="https://www.youtube.com/watch\?v\=$pVIDEO";
for f in $sub_formats
do
CMD="youtube-dl --skip-download --write-auto-sub --no-check-certificate --sub-lang $LANG --sub-format $f https://www.youtube.com/watch\?v\=${1}"
if isDebug; then
echo ""$f
echo $CMD
fi
eval $CMD
done
}
write_img_2_storage() {
IMG="${1}"
DISKNR="${2}"
FUNCNAME=${0}
isDebug && echo $@
if [ $# -eq 2 ] && string_contains "$(file $IMG)" "MBR boot sector" && [[ $(hdiutil imageinfo -format $IMG) == "RAW*" ]] && isNumeric "$DISKNR";
then
CMD="sudo dd if=${IMG} of=/dev/rdisk${DISKNR} bs=1m"
isDebug && echo $CMD
$(echo $CMD)
elif [ "${1}" = "-h" ] || [ "${1}" = "--help" ]
then
_print_usage
return 0
else
echo "Errors: look up usage with $FUNCNAME --help"
[ $# -lt 2 ] && echo "arguments missing"
[ $# -gt 0 ] && ! string_contains "$(file $IMG)" "MBR boot sector" && echo "MBR boot sector is missing in $IMG"
[ $# -gt 0 ] && ! [[ $(hdiutil imageinfo -format $IMG) == "RAW*" ]] && echo "do the conversion with echo \"hdiutil convert -format UDRW -o $IMG source.iso\""
! isNumeric "$DISKNR" && echo "$DISKNR should be a number: execute \"diskutil list\" again and look for the right number"
return 1
fi
_print_usage() {
echo "usage: $FUNCNAME <path to bootable disk image> <disk-nr of removable storage device (e.g. USB-Stick)"
echo "To find out the disk number execute diskutil list w/ and w/o the storage device plugged in"
echo "Look for an entry like \"/dev/disk4 (external, physical)\""
echo "the example above would lead to the disk-nr »4«"
echo "Create the diskimage-file with"
echo "hdiutil convert -format UDRW -o target.img source.iso"
echo ""
}
}
mancat () {
MAN_OUTPUT_FOLDER="$TMP/manoutput"
[ -d $MAN_OUTPUT_FOLDER ] || mkdir -p "$MAN_OUTPUT_FOLDER"
TARGET_MAN_FILE="$MAN_OUTPUT_FOLDER/man_${1}.txt"
[ -f $TARGET_MAN_FILE ] || man "${1}" > "$TARGET_MAN_FILE"
cat "$MAN_OUTPUT_FOLDER/man_${1}.txt"
}
update_video_content () {
cd $MOVIESe;
#ls -G -1 ./**/*.(mp4|mkv|webm|mov) > $MOVIESe/TOC.txt;
cd $OLDPWD;
}
phpserve() {
URL=$([ -n "${1}" ] && echo "${1}" || echo "localhost")
PORT=$([ -n "${2}" ] && echo "2" || echo "8080")
DOCROOT=$([ -n "${3}" ] && echo "3" || echo ".")
php -S "$URL:$PORT" -t $DOCROOT
}
chhE () {
CMD='history | grep -i -E "[^a-zA-Z0-9_]{1}'${1}'[^a-zA-Z0-9_]{1}"';
echo $CMD;
eval $CMD;
}
allcommands () {
for i in $(list_path)
do
echo "==> $i <=="
for cmd in $(ls -1 $i)
do
echo "$cmd"
isDebug && echo "$i/$cmd"
done
done
}
all_commands () {
for i in $(list_path)
do
echo "==> $i <=="
ls -1l $i
#for cmd in $(ls -1 $i)
# do
# echo "$cmd"
# isDebug && echo "$i/$cmd"
# done
done
}
pink2() { echo "\033[1;35m${1}\033[00m"; }
pink() { echo "${COLOR_Purple}${1}${W}"; }
red() { echo "${COLOR_Red}${1}${W}"; }
blue() { echo "${COLOR_Blue}${1}${W}"; }
green() { echo "${COLOR_Green}${1}${W}"; }
Pink() { echo "${COLOR_Purple}${1}${W}"; }
#startsWithDash () {
# PARAM="${1}"
# isDebug && echo $PARAM