-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc_functions
More file actions
589 lines (536 loc) · 12.8 KB
/
Copy path.bashrc_functions
File metadata and controls
589 lines (536 loc) · 12.8 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
function append_string()
{
for filename in $(find . -type f -regex ".*\.\(c\|h\)"); do
echo $filename
echo sed -i "s/$1/$1$2/g" $filename
sed -i "s/$1/$1$2/g" $filename
done
}
function gvim_init_remote()
{
gvim --servername $1
}
function gvim_open_remote()
{
gvim --servername $1 --remote-tab-silent $2
}
function gvim_open_remote_vertical_split()
{
gvim -O --servername $1 --remote-silent $2 $3
}
function gvimr_GVIM_func()
{
gvim_open_remote GVIM $1
}
function gvimr_init()
{
export thiswindow=$(now)
gvim_init_remote $thiswindow
}
function gvimr()
{
gvim_open_remote $thiswindow $1
}
function gvimrv()
{
gvim_open_remote_vertical_split $thiswindow $1 $2
}
#plugin aliases
#alias gvimr_init='gvim_init_remote GVIM'
#alias gvimr='gvim_open_remote GVIM'
#alias gvimr_init1='gvim_init_remote GVIM1'
#alias gvimr1='gvim_open_remote GVIM1'
#alias tag='echo "starting ctags ...";ctags -R * ;echo "ctags done";echo "starting gtags ...";gtags;echo "gtags done"'
#bash function aliases
alias oft='openfile "gvimr_GVIM_func"'
alias of='openfile vim'
alias ofr='openfile_gvimr'
alias ofg='openfile_godir'
alias ofrp4='openfile_reconcile_p4'
alias fif='findinfile "-i -n"'
alias fife='findinfile_ext "-i -n"'
alias fifg='findinfile'
alias fifw='findinfile "-i -n -w"'
alias fifbase='findinfilebase'
alias archivenow='create_archive_tar_gz'
function showp4
{
local hist=$(p4 changes ... | cut -d " " -f 2 | xargs -I{} p4 describe -s {} | sed -n '/Change/,/Fixes/p ; /^\.\.\./p' | sed '/^$/d')
echo "$hist"
}
function showp4opened
{
local hist=$(p4 opened -u $P4USER -c $P4CLIENT ... | cut -d " " -f 2 | xargs -I{} p4 describe -s {} | sed -n '/Change/,/Fixes/p ; /^\.\.\./p' | sed '/^$/d')
echo "$hist"
}
function p4changesperweek
{
weeknum=$1
enddate=$(date --date="${weeknum} week ago" +"%Y/%m/%d")
weeknum1=$((weeknum-1))
startdate=$(date --date="${weeknum1} week ago" +"%Y/%m/%d")
echo "Number of changes between $enddate -- $startdate\n"
p4 changes ...@$enddate,$startdate | wc -l
}
function p4shelveddiff
{
p4 describe -S -du $1
}
#GIT
alias git_oneline='git log --pretty=oneline --decorate'
alias git_pretty='git log --pretty=format:'"'"'%C(yellow)%h%Cred%d%Creset - %C(cyan)%an %Creset: %s %Cgreen(%cr)'"'"
alias git_graph='git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"'
alias git_diff='git difftool --tool="bc3"'
#P4 Alias
function p4init
{
set -a
export P4CONFIG=.p4config
export P4IGNORE=.p4ignore
. .p4config
set +a
}
function build_cscope_db_func()
{
find $PWD -name "*.c" \
-o -name "*.h" \
-o -name "*.cpp" \
-o -name "*.lua" \
-o -name "*.mk" \
-o -name "*.xml"\
-o -name "*.cfg"\
-o -name "*.ini"\
# -o -name "*.dat"\
-o -name "*.cpp" > $PWD/cscope.files
}
function tag
{
#export GTAGSCONF=/etc/gtags.conf
build_cscope_db_func
export TMPDIR=.
export GTAGSFORCEENDBLOCK=
echo "starting gtags ..."
gtags --skip-unreadable
echo "starting cscope ..."
cscope -R -b -q -k -i $PWD/cscope.files
echo "cscope done"
echo "gtags done"
}
function fpush
{
lftp -e "put -O $1 $2; Bye" -u root,root $3
}
function fget
{
lftp -e "get -O $1 $2; Bye" -u root,root $3
}
function fpushd
{
lftp -e "mirror $1 $2; Bye" -u root,root $3
}
function fgetd
{
lftp -e "mirror $1 $2; Bye" -u root,root $3
}
function countdown
{
local OLD_IFS="${IFS}"
IFS=":"
local ARR=( $1 )
local SECONDS=$(( (ARR[0] * 60 * 60) + (ARR[1] * 60) + ARR[2] ))
local START=$(date +%s)
local END=$((START + SECONDS))
local CUR=$START
while [[ $CUR -lt $END ]]
do
CUR=$(date +%s)
LEFT=$((END-CUR))
printf "\r%02d:%02d:%02d" \
$((LEFT/3600)) $(( (LEFT/60)%60)) $((LEFT%60))
sleep 1
done
IFS="${OLD_IFS}"
echo " "
}
function cmthis()
{
if [[ "qnx_ap" == $(basename $(pwd)) ]]
then
echo "Are you sure you want to clean the whole build( y/n ) ?"
read -n 1 answer
if [[ "$answer" == "n" ]]
then
echo "exiting"
return
elif [[ "$answer" == "y" ]]
then
printf "\n"
printf "STILL CAN CANCEL !!! - 10 seconds countdown \n"
countdown "00:00:10"
echo "cleaning and making build"
else
echo "invalid response"
fi
fi
make clean
make hinstall
make install
}
function p4_add()
{
find $1 -type f ! -name '*\.so*' ! -name '*\.a' ! -name '*\.Sa' ! -name '*\.pinfo' ! -name '*\.o' | p4 -x - add
}
function listfiles()
{
find $1 -type f ! -name '*\.so*' ! -name '*\.a' ! -name '*\.Sa' ! -name '*\.pinfo' ! -name '*\.o' ! -name '*\.map'
}
function find_dir_in_path()
{
local temp=$(echo $1 | grep -i $2)
if [ -n "$temp" ]
then
echo $1 | sed -re 's/(^.*'$2')(.*)/\1/I'
fi
}
# Print the current Path
function print_curr_path_dir()
{
find_dir_in_path $(pwd) $1
}
# ff
function ff()
{
txtbld
txtund
echo "find . -type f -iname '*'$*'*' -ls"
txtrst
txtblue
find . -type f -iname '*'$*'*' -ls
txtbld
txtund
echo "END RESULTS"
txtrst
}
#list files which contain the following name in current directory and sub
function ffw()
{
txtbld
txtund
echo "find . -type f -iname $1 -ls"
txtrst
txtblue
find . -type f -iname $1 -ls
txtbld
txtund
echo "END RESULTS"
txtrst
}
function ffp4()
{
txtbld
txtund
echo "find . -type f -iname '*'$*'*' -ls"
txtrst
txtblue
find . -type f -iname '*'$*'*' | xargs p4 filelog -m 1
txtbld
txtund
echo "END RESULTS"
txtrst
}
function ffwp4()
{
txtbld
txtund
echo "find . -type f -iname $1 -ls"
txtrst
txtblue
find . -type f -iname $1 | xargs p4 filelog -s -m 1
txtbld
txtund
echo "END RESULTS"
txtrst
}
#list folders which contain the following name in this directory and its sub
function ffr()
{
find . -type d -iname '*'$*'*' -ls ;
}
#open file and also cd to that directory
function openfile_godir()
{
PS3="Type a number or 'q' to quit:"
fileList=$(find . -type f -iname '*'$*'*')
txtblue
select fileName in $fileList; do
if [ -n "$fileName" ]; then
local derivedpath=$(dirname ${fileName})
cd $derivedpath
local derivedpath=$(dirname ${fileName})
local derived_file_name=$(basename ${fileName})
cd $derivedpath
vim $derived_file_name
fi
break
done
txtrst
}
#only open file and do not cd to that directory
function openfile()
{
echo "openfile '$'"
PS3="Type a number or 'q' to quit:"
fileList=$(find . -type f -iname '*'$2'*')
txtblue
select fileName in $fileList; do
if [ -n "$fileName" ];
then
if [ -z "$3" ]; then
$1 ${fileName}
else
$1 +$3 ${fileName}
local derivedpath=$(dirname ${fileName})
cd $derivedpath
fi
fi
break
done
txtrst
}
function openfile_p4_reconcile()
{
PS3="Type a number or 'q' to quit:"
fileList=$(find . -type f -iname '*'$*'*')
txtblue
select fileName in $fileList; do
if [ -n "$fileName" ]; then
p4 reconcile -e ${fileName}
fi
break
done
txtrst
}
#goto directory of this file
function gofile()
{
PS3="Type a number or 'q' to quit:"
txtbld
txtund
fileList=$(find . -type f -iname '*'$*'*')
txtrst
txtblue
select fileName in $fileList; do
if [ -n "$fileName" ]; then
local derivedpath=$(dirname ${fileName})
cd $derivedpath
fi
break
done
txtrst
}
#goto this directory
function godir()
{
PS3="Type a number or 'q' to quit:"
txtbld
txtund
echo "find . -type d -iname '*'$*'*'"
txtrst
folderList=$(find . -type d -iname '*'$*'*')
txtblue
select folderName in $folderList; do
if [ -n "$folderName" ]; then
cd ${folderName}
fi
break
done
txtrst
}
function godirw()
{
PS3="Type a number or 'q' to quit:"
txtbld
txtund
echo "find . -type d -iname $*"
txtrst
folderList=$(find . -type d -iname $*)
txtblue
select folderName in $folderList; do
if [ -n "$folderName" ]; then
cd ${folderName}
fi
break
done
txtrst
}
# find this text in the file
function findinfile()
{
txtbld
txtund
txtred
echo "find . -type f -iname '*'$2'*' -print | xargs grep $1 $3"
txtrst
txtblue
find . -type f -iname '*'$2'*' -print | xargs grep $1 "$3"
txtrst
txtred
echo "RESULTS END"
txtrst
}
function findinfile_ext()
{
txtbld
txtund
txtred
echo "find . -type f -iname '*'$2 -print | xargs grep $1 $3"
txtrst
txtblue
find . -type f -iname '*'$2 -print | xargs grep $1 "$3"
txtrst
txtred
echo "RESULTS END"
txtrst
}
#dont know
function listinfile()
{
PS3="Type a number or 'q' to quit:"
echo "find . -type f -iname '*'$1'*' -print | xargs grep -i $2 "
fileList=$(find . -type f -iname '*'$1'*' -print | xargs grep -i $2 )
fileList_final=$($fileList | sed -re 's/(^.*':')(.*)/\1/I')
select fileName in $fileList_final; do
if [ -n "$fileName" ]; then
vim ${fileName}
fi
break
done
}
function selectdirectory()
{
printf "Please select folder:\n"
select d in */; do test -n "$d" && break; echo ">>> Invalid Selection"; done
cd "$d" && pwd
}
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$@\a\]"
PS1=${ORIG}${TITLE}
}
function txtbld() {
if hash tput 2>/dev/null; then
tput bold #bold
else
:
fi
}
function txtund() {
if hash tput 2>/dev/null; then
tput sgr 0 1 #underline
else
:
fi
}
function txtrst() {
if hash tput 2>/dev/null; then
tput sgr0 #Reset
else
:
fi
}
function txtred() {
if hash tput 2>/dev/null; then
tput setaf 1 #red
else
:
fi
}
function txtblue() {
if hash tput 2>/dev/null; then
tput setaf 4 #blue
else
:
fi
}
# function create_gitrepo() {
# curl -i -H 'Authorization: token fd64cd5450e4b9dedfec235d534fd28b6696814e' -d '{ "name": "'$1'", "auto_init": true, "private": false, "gitignore_template": "nanoc" }' https://api.github.com/graphql
# }
#function create_gitrepo() {
#curl -i -H 'Authorization: token fd64cd5450e4b9dedfec235d534fd28b6696814e' -d '{ "name": "'$1'", "auto_init": true, "private": false, "gitignore_template": "nanoc" }' https://api.github.com/user/repos
#}
function create_gitrepo() {
if [ -z "$1" ]
then
echo "input the authorization token -> github ->settings -> Developer Settings -> personal access token \n"
read token
else
token=$1
fi
if [ -z "$2" ]
then
echo "input the authorization token -> github ->settings -> Developer Settings -> personal access token \n"
read repo_name
else
repo_name=$2
fi
#echo curl -i -H 'Authorization: token '$token'' -d '{ "name": "'$repo_name'", "auto_init": true, "private": false, "gitignore_template": "nanoc" }' https://api.github.com/user/repos
curl -i -H 'Authorization: token '$token'' -d '{ "name": "'$repo_name'", "auto_init": true, "private": false, "gitignore_template": "nanoc" }' https://api.github.com/user/repos
}
function hexdump_word()
{
dd if=$1 bs=4 2>/dev/null | hexdump -v -e '"%08_ax: "' -e ' 4/4 "%08x " " |"' -e '16/1 "%_p" "|\n"'
}
function hexdump_()
{
hexdump -v -e '"%08_ax: "' -e ' 4/4 "%08x " " |"' -e '16/1 "%_p" "|\n"' $1
}
__desc_chg()
{
echo "$1"
num=`echo $1 | awk '{print $2}'`
p4 opened -c $num 2>&1 | awk '{print " "$1,$2,$3,$6}'
p4 describe $num | grep -i orbit
echo
}
__desc_shelved_chg()
{
echo "$1"
num=`echo $1 | awk '{print $2}'`
p4 describe -S $num 2>&1 | awk '{print " "$1,$2,$3,$6}'
echo
}
__p4pending()
{
__desc_chg "Change default by $P4USER@$P4CLIENT *pending*"
p4 changes -u $P4USER -c $P4CLIENT -s pending | sort -k2 -n | while read -r l;
do
__desc_chg "$l";
done
}
__p4shelved()
{
__desc_chg "Change default by $P4USER@$P4CLIENT *pending*"
p4 changes -u $P4USER -c $P4CLIENT -s shelved | sort -k2 -n | while read -r l;
do
__desc_shelved_chg "$l";
done
}
alias p4pending='__p4pending'
alias p4shelved='__p4shelved'
addcc()
{
ccollab admin review create --title "$1"
ccollab addchangelist last $2
}
p4weekly()
{
DATE=$1
WEEKS=$2
for i in {0.."$WEEK"}
do
NEXT_DATE=$(date +%Y/%m/%d -d "$DATE + $i day")
echo "$NEXT_DATE"
done
}