-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.aliases
executable file
·1712 lines (1451 loc) · 49.3 KB
/
.aliases
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
fualias() { echo -n ""; }
fuinit() {
fualias $@ ; unset -f fualias; fualias () { echo -n ""; }
}
function function_exist_check() {
if (declare -f -F "$@" > /dev/null); then
return 0
else
return 1
fi
}
# function cd() {
# builtin cd "$@"
# if [ $? -ne 0 ]; then
# return
# fi
# ls --color=auto -AF
# echo ""
# pwd
# }
# zsh 아니면 cd 명령어는 기존대로 처리
if ( grep -q "/zsh" <<< "$SHELL" ); then
function cdb() {
builtin cd "$@"
# ls --color=auto -AF
# echo ""
pwd
}
if [ -z "$_ZO_DATA_DIR" ]; then
source $HOME/.dotfiles/script/cdscript.sh
fi
fi
function fg() {
if [ $# -eq 1 ] && [[ "$@" = "-" ]]; then
builtin fg %-
else
builtin fg %"$@"
fi
}
if [ -n "$(command -v nvim)" ]; then
alias nvi='nvim'
alias vi='nvim'
alias vim='nvim'
alias ovim="$(/bin/bash -c 'which vim')"
fi
alias vit="vi -c ':term'"
# enable color support of ls and also add handy aliases
if [ -f $HOME/.dotfiles/.shell_color.sh ]; then
. $HOME/.dotfiles/.shell_color.sh
elif [ -f $HOME/.shell_color.sh ]; then
. $HOME/.shell_color.sh
fi
alias grepo="grep --color=auto -rnIH"
alias grepi="grep --color=auto -rnIHP"
alias grepapi="grep --color=auto --exclude-dir=hmapi -rnIHP"
# alias grepf="grep --color=auto -rnIHF"
alias grepq="grep --color=auto -rnIHF"
# ssh
if [ -f $HOME/.ssh/config ]; then
alias ssh='ssh -F $HOME/.ssh/config -i $HOME/.ssh/id_rsa -o UserKnownHostsFile=$HOME/.ssh/known_hosts'
alias scp='scp -F $HOME/.ssh/config -i $HOME/.ssh/id_rsa -o UserKnownHostsFile=$HOME/.ssh/known_hosts'
alias sshinit='ssh-keygen -f $HOME/.ssh/known_hosts -R '
alias ibrew="arch -x86_64 /usr/local/bin/brew"
fi
# some more ls aliases
# alias ll='ls -1shF'
# alias lla='ls -1ashF'
unalias ll
function ll()
{
lsoutput=$( ls -lhF --color=always $@ )
size_col_width=15
echo "$lsoutput" | head -n 1
echo "$lsoutput" | tail -n +2 | awk '{
printf "%-7s ", $5
for(i=9;i<=NF;i++) printf "%s ", $i;
print ""
}'
}
function lla()
{
lsoutput=$( ls -alhF --color=always $@ )
size_col_width=15
echo "$lsoutput" | head -n 1
echo "$lsoutput" | tail -n +2 | awk '{
printf "%-7s ", $5
for(i=9;i<=NF;i++) printf "%s ", $i;
print ""
}'
}
# alias ll='ls -lhF'
# alias lla='ls -alhF'
alias l='ls -hCF'
alias la='ls -ahCF'
# alias l='ls -hCF -w 160'
# alias la='ls -ahCF -w 160'
alias le='ls -lhF'
alias lw='ls -shCF -w 180'
alias lea='ls -alhF'
alias af='ls -shCF -w 180'
alias sf='ls -shF1'
# alias f='ls -hF'
alias f='ls -1shF'
# alias fa='ls -shaCF -w 60'
alias fa='ls -1shaF'
alias fs='ls -1shF'
alias j='ls -shCF'
alias ja='ls -shaCF'
# alias j='ls -shCF -w 180'
# alias ja='ls -shaCF-w 180'
# alias ja='ls -shaCF'
alias jj='ls -1shF'
alias jja='ls -1shaF'
alias ef='ls -lhF'
alias fe='ls -alhF'
alias wf='ls -ohF'
alias fe='ls -alhF'
alias kd='ls -shCF -w 60'
# alias l='ls -shCF -w 60'
# alias l='ls -1shF'
alias psa='ps -aef'
function psf() {
process_name="$@"
ps -aef | head -n1
# ps -aef | grep --color=always "$process_name" | grep -v "grep --color.*always.*$process_name"
if [ $# -eq 0 ]; then
ps -aef
return 0
fi
IFS='' process_names=( $@ )
processes="$(ps -aef)"
for process_name in "${process_names[@]}" ; do
# bash -c "echo -e \"${processes}\" | grep --color=always \"$process_name\" | grep -v \"grep --color.*always.*$process_name\""
echo -e "${processes}" | grep -a --color=always "$process_name" | grep -a -v "grep --color.*always.*$process_name"
done
}
function perft() {
if [ $# -eq 0 ]; then
perf top
return 0
fi
IFS='' process_names=( $@ )
process_str=""
for process_name in "${process_names[@]}" ; do
process_str="$process_str,$(pidof "$process_name" | tr ' ' ',')"
done
if [ "${process_str:0:1}" = "," ]; then
process_str="${process_str:1}"
fi
# echo "$process_str"
perf top --pid=$(echo "$process_num")
}
function topd() {
process_name="$@"
if [ $# -eq 0 ]; then
top -b -n 1
return 0
fi
IFS='' process_names=( $@ )
processes="$(top -b -n 1)"
echo "$processes" | head -n 7
for process_name in "${process_names[@]}" ; do
echo -e "${processes}" | grep -a --color=always "$process_name" | grep -a -v "grep --color.*always.*$process_name"
done
}
function psu() {
process_name="$@"
ps -aux | head -n1
# ps -aux | grep --color=always "$process_name" | grep -v "grep --color.*always.*$process_name"
if [ $# -eq 0 ]; then
ps -aux
return 0
fi
IFS='' process_names=( $@ )
processes="$(ps -aux)"
for process_name in "${process_names[@]}" ; do
# bash -c "echo -e \"${processes}\" | grep --color=always \"$process_name\" | grep -v \"grep --color.*always.*$process_name\""
echo -e "${processes}" | grep -a --color=always "$process_name" | grep -a -v "grep --color.*always.*$process_name"
done
}
function watcha() {
if [ $# -eq 2 ]; then
watch --color -n $1 -x bash -c "source ~/.aliases; $2"
else
watch --color -n 1 -x bash -c "source ~/.aliases; $@"
fi
}
alias makef='make -j8'
# add export path
if [ -d $HOME/.dotfiles/.bin/ ]; then
if ! grep -q "$HOME/.dotfiles/.bin" <<< "$PATH"; then
export PATH=$HOME/.dotfiles/.bin:$PATH
fi
fi
if [ -n "$(command -v 'code-insiders')" ]; then
alias code='code-insiders'
fi
# =======================================================================
# wsl command
if [ -n "$(uname -r | grep 'WSL')" ]; then
if [ "$(command -v code)" = "" ]; then
codepath="/mnt/c/jvscode/Code.exe"
if [ -f $codepath ] && [ ! -f $HOME/.local/bin/code ]; then
[ ! -d $HOME/.local/bin/ ] && mkdir -p $HOME/.local/bin/
ln -s $codepath $HOME/.local/bin/code
fi
unset codepath
fi
# windows + explorer
function epl() {
if [[ "$@" = "" ]]; then
/mnt/c/WINDOWS/explorer.exe .
return
fi
if [ -d "$@" ]; then
builtin cd "$@"
/mnt/c/WINDOWS/explorer.exe .
builtin cd - > /dev/null
return
fi
/mnt/c/WINDOWS/explorer.exe .
}
# function code() {
# if [[ "$@" = "s" ]]; then
# /mnt/c/jvscode/Code.exe ./
# else
# /mnt/c/jvscode/Code.exe $@
# fi
# }
function goc() { cd /mnt/c/$@; }
function god() { cd /mnt/d/$@; }
function goe() { cd /mnt/e/$@; }
function govscode() { cd /mnt/c/jvscode/data/user-data/User/$@; }
function gohome() { cd /mnt/c/Users/ghkd0/$@; }
function golog() { cd /mnt/e/mylog/$@; }
function godown() { cd /mnt/c/Users/ghkd0/Downloads/$@; }
function godesktop() { cd /mnt/c/Users/ghkd0/Desktop/$@; }
# "/mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/BComp.exe"
# alias diffb='"/mnt/c/Program Files/Beyond Compare 4/BComp.exe"'
alias diffb='~/.bcomp.sh'
alias curla="/mnt/c/Users/ghkd0/Videos/.aaa_testcurl.sh"
alias curlq="/mnt/c/Users/ghkd0/Videos/.qqq_testcurl.sh"
alias curls="/mnt/c/Users/ghkd0/Videos/.rrr_testcurl.sh"
[[ "$TERM_PROGRAM" != "vscode" ]] && (builtin cd $HOME)
# mac command
elif [[ "$(uname -s)" = "Darwin" ]]; then
# alias code="/Applications/'Visual Studio Code.app'/Contents/Resources/app/bin/code"
# .bin/code
# if [ -d "/Applications/Cursor.app" ]; then
# alias code="/Applications/Cursor.app/Contents/Resources/app/bin/code"
# elif [ -d "/Applications/Visual Studio Code.app" ]; then
# alias code="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
# fi
# export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
# alias diffb='~/.bcomp'
# macos
if [ -d "/Applications/Hex Fiend.app" ]; then
alias hxd='open -a /Applications/Hex\ Fiend.app'
alias hexvi='open -a /Applications/Hex\ Fiend.app'
fi
alias diffb='"/Applications/Beyond Compare.app/Contents/MacOS/BComp"'
alias which="$(/bin/bash -c 'which which' 2>/dev/null)"
alias ldd="otool -L"
# vim -> mvim, nvim
if [ -d "/Applications/MacVim.app/" ]; then
alias mvi='/Applications/MacVim.app/Contents/bin/vim'
alias mvim='/Applications/MacVim.app/Contents/bin/mvim'
alias macvim='/Applications/MacVim.app/Contents/bin/vim'
# alias vi="/Applications/MacVim.app/Contents/bin/vim"
# alias vim="/Applications/MacVim.app/Contents/bin/vim"
fi
if [ -d "/Applications/goneovim.app" ]; then
alias gvim='/Applications/goneovim.app/Contents/MacOS/goneovim'
alias gi='/Applications/goneovim.app/Contents/MacOS/goneovim'
fi
# brew install findutils
if [ -f /opt/homebrew/bin/gxargs ]; then
alias xargs="/opt/homebrew/bin/gxargs"
fi
function godown() { cd $HOME/Downloads/$@; }
function godoc() { cd $HOME/Documents/$@; }
function gonote() { cd $HOME/.notepad/$@; }
alias notecode="code $HOME/.notepad/"
function gont() { cd $HOME/.notepad/$@; }
# go google drive
function gogd() { cd "$HOME/GoogleDrive/$@"; }
function godrive() { cd "$HOME/GoogleDrive/$@"; }
function goicloud() { cd "$HOME/Library/Mobile Documents/com~apple~CloudDocs/$@"; }
function goissue() { cd $HOME/issue/$@; }
# ppk to pem
function ppktopem() {
if [ "$(command -v puttygen)" = "" ]; then
echo "install putty first"
echo "brew install putty"
return
fi
filename=$@
extname="${filename:$(expr ${#filename} - 4)}"
if [[ "$extname" != ".ppk" ]]; then
echo "not ppk file"
return
fi
pemname=$(echo "$filename" | sed 's/.ppk$/.pem/')
puttygen "$filename" -O private-openssh -o "$pemname"
}
function pemtoppk() {
if [ "$(command -v puttygen)" = "" ]; then
echo "install putty first"
echo "brew install putty"
return
fi
filename=$@
puttygen "$filename" -o "${filename}.ppk"
}
function ddns_set() {
ddns_script_path="$HOME/GoogleDrive/develop/settings/ddns_cloudflare.sh"
if [ ! -x $ddns_script_path ]; then
echo "$ddns_script_path"
echo "not found ddns script path"
return 1
fi
"$ddns_script_path" $@
}
alias ddnset="ddns_set"
function ddnsvi() {
ddns_script_path="$HOME/GoogleDrive/develop/settings/ddns_cloudflare.sh"
if [ ! -x $ddns_script_path ]; then
echo "$ddns_script_path"
echo "not found ddns script path"
return 1
fi
vim "$ddns_script_path"
}
alias keyvi="vi \"$HOME/GoogleDrive/keys/keys.txt\""
alias gosr="cd $HOME/src"
alias gosrc="cd $HOME/src"
# cd practice directory
alias gotest="cd $HOME/src/testsrc"
alias gocert="cd $HOME/Documents/cert"
alias curla="$HOME/curltest/.aaa_testcurl.sh"
alias curls="$HOME/curltest/.sss_testcurl.sh"
alias curld="$HOME/curltest/.ddd_testcurl.sh"
alias curlq="$HOME/curltest/.qqq_testcurl.sh"
alias curle="$HOME/curltest/.eee_testcurl.sh"
alias curlr="$HOME/curltest/.rrr_testcurl.sh"
alias curlg="$HOME/curltest/.ggg_testcurl.sh"
alias curlavi="vim $HOME/curltest/.aaa_testcurl.sh"
alias curlsvi="vim $HOME/curltest/.sss_testcurl.sh"
alias curldvi="vim $HOME/curltest/.ddd_testcurl.sh"
alias curlqvi="vim $HOME/curltest/.qqq_testcurl.sh"
alias curlevi="vim $HOME/curltest/.eee_testcurl.sh"
alias curlrvi="vim $HOME/curltest/.rrr_testcurl.sh"
alias curlgvi="vim $HOME/curltest/.ggg_testcurl.sh"
alias dockoff="defaults write com.apple.dock autohide-delay -float 1000; killall Dock"
alias dockon="defaults delete com.apple.dock autohide-delay; killall Dock"
# explorer
alias epl="open ."
alias expl="open ."
alias gk="/opt/homebrew/bin/gk"
function aidi() {
$HOME/.dotfiles/script/aider.sh
}
function aidic() {
rm -f $HOME/.config/aider/history.input.md
}
function aidicc() {
rm -f $HOME/.config/aider/history.chat.md
}
function aidica() {
rm -f $HOME/.config/aider/history.chat.md
rm -f $HOME/.config/aider/history.input.md
}
else
alias diffb='~/.bcomp.sh'
# .bin/code
# if [ -n "$(command -v cursor)" ]; then
# alias code="cursor"
# fi
fi
# =======================================================================
# diffdirectory - diffdir
function diffdir()
{
directory_1="v5.0"
directory_2="v5.0.2_2"
file1="$directory_1/$@"
file2="$directory_2/$@"
if [ ! -f $file1 ]; then
echo "$file1 not exist"
return
elif [ ! -f $file2 ]; then
echo "$file2 not exist"
return
fi
diffb "$file1" "$file2"
}
# absolute path
alias abs='readlink -e'
alias rpth='readlink -e'
alias grepno="$HOME/.dotfiles/grepscript/grepno"
alias grepn="$HOME/.dotfiles/grepscript/grepn"
alias grepm="$HOME/.dotfiles/grepscript/grepm"
alias agrepno="$HOME/.dotfiles/grepscript/agrepno"
alias agrepn="$HOME/.dotfiles/grepscript/agrepn"
alias agrepm="$HOME/.dotfiles/grepscript/agrepm"
# 반복문에서 echo 및 sed 시 성능이 너무 떨어짐
# agrepn 단독 사용 시 0.04sec 걸리는 명령어가 grepnz 사용 시 3.5sec 까지 늘어남.
# 따라서 반복문 내에서 echo 와 sed 사용을 최소화
# for line in "${output_array[@]}"; do
# if [ -z "$line" ]; then
# continue
# fi
# # results+=("${line}")
# # results=$(echo "$results\n${line}")
# # IFS=$'\n' grep_output=( $(echo "$line" | sed 's/ | /\n/') )
# # 출력 공백 제거
# # context=$(echo "${grep_output[2]}" | sed 's/\[K[ \t]*/\[K/g')
# # results=$(echo "$results\n${context} | ${grep_output[1]}")
# # results=$(echo "$results\n${grep_output[2]} | ${grep_output[1]}")
# done
alias fif="fzf --bind 'enter:become(command -v code >/dev/null 2>&1 && code {} || vi {})'"
# alias fnf="$HOME/.dotfiles/fzfscript/grepff"
# alias fmf="$HOME/.dotfiles/fzfscript/grepff -f"
alias gpf="$HOME/.dotfiles/fzfscript/grepff"
alias gpfh="$HOME/.dotfiles/fzfscript/grepff -f"
alias gph="$HOME/.dotfiles/fzfscript/grepff -f"
alias grepf="$HOME/.dotfiles/fzfscript/grepff"
alias grepfh="$HOME/.dotfiles/fzfscript/grepff -f"
alias greph="$HOME/.dotfiles/fzfscript/grepff -f"
alias grepff="$HOME/.dotfiles/fzfscript/grepff"
alias gnf="$HOME/.dotfiles/fzfscript/grepnfzf"
alias gff="$HOME/.dotfiles/fzfscript/grepnfzf"
alias gmf="$HOME/.dotfiles/fzfscript/grepmfzf"
alias gmff="$HOME/.dotfiles/fzfscript/grepmfzf"
# fzfcode
if [ -n "$(command -v fzf)" ]; then
if (alias fzf >/dev/null 2>&1); then
unalias fzf
fi
alias fzf="fzf -e --ansi --height 40% --layout=reverse --bind 'ctrl-a:half-page-up' --bind 'ctrl-d:half-page-down'"
# if (declare -f -F "$@" > /dev/null); then
# unset -f fzf
# fi
# whence -p fzf # command in zsh
# local FU_FZF_BIN_PATH="$(/bin/which fzf)"
function faf() {
# TODO : -m 등 옵션값 처리하지 못함. 해당 방법 모색
# local FU_FZF_BIN_PATH="$(/bin/which fzf)"
[ $# -ge 2 ] && echo "too many arguments" && return
if [ $# -eq 1 ]; then
if [ ! -d "$@" ]; then
echo "$@ not directory"
return
fi
builtin cd $@
fzf -e --ansi --height 40% --layout=reverse --bind 'ctrl-a:half-page-up' --bind 'ctrl-d:half-page-down'
builtin cd - > /dev/null
return
fi
fzf -e --ansi --height 40% --layout=reverse --bind 'ctrl-a:half-page-up' --bind 'ctrl-d:half-page-down'
}
fi
function didiff() {
local codepath=vimdiff
local codeopt=""
[ -n "$(command -v code)" ] && codepath=code && codeopt="--diff"
[ -n "$(command -v 'code-insiders')" ] && codepath=code-insiders && codeopt="--diff"
if [ $# -ne 2 ]; then
echo "wrong argument"
return;
fi
if [ ! -f "$1" ];then
echo "'$1' file is not exist"
return
fi
if [ ! -f "$2" ];then
echo "'$2' file is not exist"
return
fi
$codepath $codeopt "$1" "$2"
}
function encoding_ls()
{
find . -type f -exec grep -I -q . {} \; -print | xargs -I{} file -i {}
}
function encoding_euckr_to_utf8()
{
# euc_krs=( $(find . -name "*" -type f -exec file -i {} \; | grep "iso-8859-1" | awk -F ":" '{print $1}') )
# get not binary file list
# euckrs=( $(find . -type f -exec grep -I -q . {} \; -print) )
euc_krs=( $(find . -type f -exec grep -I -q . {} \; -print | xargs -I{} file -i {} | grep "iso-8859-1" | awk -F ":" '{print $1}') )
for file in "${euc_krs[@]}" ; do
echo "Converting $file to UTF-8"
# euc-kr -> utf-8, save to test.c.new
iconv -c -f euc-kr -t utf-8 "$file" > "$file.new"
# remove test.c
rm -f "$file"
# mv test.c.new test.c
mv "$file.new" "$file"
done
}
# alias direj="di $(find . -name '*.rej' -type f | head -n 1 | sed 's/....$//') $(find . -name '*.rej' -type f | head -n 1)"
function direj()
{
find_result=$(find . -name '*.rej' -type f)
rej_file=$(echo "$find_result" | head -n 1)
org_file=$(echo "$rej_file" | sed 's/....$//')
echo "$rej_file"
remains=$(echo "$find_result" | wc -l)
echo "remain : $remains"
di "$rej_file" "$org_file"
}
function mvrej()
{
rej_file=$(find . -name '*.rej' -type f | head -n 1)
echo "$rej_file"
if [ ! -d $HOME/rej ]; then
mkdir $HOME/rej/
fi
cp --parents $rej_file $HOME/rej/
rm -f "$rej_file"
}
# rollback rej
function rbrej()
{
res=$(find $HOME/rej -type f -printf "%T@ %p\n" | sort -n | tail -n1 | cut -d" " -f2-)
if [ "$rej" = "" ]; then
echo "empty in rej"
return ;
fi
resto=."$(echo "$res" | sed "s|$HOME/rej||")"
rb_path="$(dirname $resto)"
echo $res
mv "$res" "$rb_path"
}
function toucha() { touch $@; chmod 755 $@; }
function psv() {
ps -aef | head -n 1
ps -aef | grep "$@" | grep -v "grep --color=auto $@" | grep "$@"
}
function makectags() { ctags --tag-relative --langmap=C:.c.h.l.y --c-kinds=+p+l --languages=C --fields=+l $@ -f .tags --sort=foldcase -R ./*; }
function makepytags() { ctags --tag-relative --langmap=Python:.py --languages=Python --fields=+l $@ --sort=foldcase -R ./*; }
alias guifiles='vim -c :UpdateTypesFileOnly -c :q'
function maketaghl() {
if [ ! -f ~/.vim/plugin/TagHighlight.vim ]; then
echo "no TagHighlight.vim plugin"
return
fi
test ! -f taghl_config.txt && touch taghl_config.txt
echo "IncludeLocals:True" > taghl_config.txt
echo "TagFileName:.tags" >> taghl_config.txt
echo -n "UserLibraries:" >> taghl_config.txt
}
function clearsslkeylog() {
if [ "$SSLKEYLOGFILE" = "" ]; then
echo "SSLKEYLOGFILE is not defined"
return
fi
echo -n "" > $SSLKEYLOGFILE
}
# find . ! \( -type d \( -path "./test1" -o -path "./test2" \) -prune \) -type f -and ! -name "LICENSE.txt" -and ! -name "readme.txt" -and -name "*.txt"
# alias findsrc='fualias() { find . ! \( -type d \( -path "./httpgw_oldssl" \) -prune \) -regex ".*\.\(c\|h\|y\|l\|py\)" -type f -exec grep -Hn --color "$@" {} \; ; }; fuinit'
# fd glob pattern
alias fdl="fd -H -t f -g"
alias fdi="fd -H -I"
function findsrc() {
local ext="\(c\|cpp\|h\|y\|l\|py\)"
find . ! \( -type d \( -path "./httpgw_oldssl" \) -prune \) -regex ".*\.$ext" -type f -exec grep -HnP --color=always "$@" {} \; |
sed -e "/Binary file .* matches/d" |
sed -e "s/\:\[m\[K\s*/ |[m[K /2"
# sed -e "s/\:/ | /2" -e "s| \| \[m\[K\s*| \| [m[K|"
}
function afindsrc() {
local curpwd=$(pwd)
if [[ "$curpwd" != "/" ]]; then
curpwd="${curpwd}/"
fi
local ext="\(c\|cpp\|h\|y\|l\|py\)"
find . ! \( -type d \( -path "./httpgw_oldssl" \) -prune \) -regex ".*\.$ext" -type f -exec grep -HnP --color=always "$@" {} \; |
sed -e "/Binary file .* matches/d" |
sed -e "s|^|${curpwd}|1" -e "s|\:\[m\[K\s*|[m[K\n|2"
# sed -e "s|^|${curpwd}|1" -e "s/\:/\n/2" -e "s|\n\[m\[K\s*|\n[m[K|"
}
function findex() {
local curpwd=$(pwd)
if [ $# -lt 2 ]; then
echo "wrong argument"
return ;
fi
if [[ "$curpwd" != "/" ]]; then
curpwd="${curpwd}/"
fi
# argument get last index value
keyword="${@:${#}:1}"
# local ext="\($1"
# fd - no \ char
local ext="($1"
local exts=()
for _ext in "$@"; do
exts+=("$_ext")
done
unset "exts[${#exts[@]}]"
exts=("${exts[@]:1}")
# local ext="\(c\|cpp\|h\|y\|l\|py\)"
for (( i=1; i<${#exts[@]}; i++ )); do
# ext+="\|${exts[$i]}"
ext+="|${exts[$i]}"
done
unset exts
# ext+="\)$"
ext+=")$"
# find . -regex ".*\.$ext" -type f -exec grep -HnP --color=always "$keyword" {} \; |
fd --regex ".*\.$ext" --type file --color=never --follow --hidden --no-ignore -X grep -lI . |
xargs -d '\n' -I{} grep -HnP --color=always "$keyword" {} |
sed -e "s/\:\[m\[K\s*/ |[m[K /2"
}
function findexa() {
local curpwd=$(pwd)
if [ $# -lt 2 ]; then
echo "wrong argument"
return ;
fi
if [[ "$curpwd" != "/" ]]; then
curpwd="${curpwd}/"
fi
keyword="${@:${#}:1}"
# local ext="\($1"
# fd - no \ char
local ext="($1"
local exts=()
for _ext in "$@"; do
exts+=("$_ext")
done
unset "exts[${#exts[@]}]"
exts=("${exts[@]:1}")
# local ext="\(c\|cpp\|h\|y\|l\|py\)"
for (( i=1; i<${#exts[@]}; i++ )); do
# ext+="\|${exts[$i]}"
ext+="|${exts[$i]}"
done
unset exts
# ext+="\)$"
ext+=")$"
# find . -regex ".*\.$ext" -type f -exec grep -HnP --color=always "$keyword" {} \; |
fd --regex ".*\.$ext" --type file --color=never --follow --hidden --no-ignore -X grep -lI . |
xargs -d '\n' -I{} grep -HnP --color=always "$keyword" {} |
sed -e "s|^|${curpwd}|1" -e "s|\:\[m\[K\s*|[m[K\n|2"
}
function findall() { find . -name "*" -type f -exec grep -HnP --color "$@" {} \; ; }
function catcrlf() {
if [ ! -f "$@" ]; then
echo "file not found"
return 1
fi
cat -A "$@" | sed 's/\$$/\r/'
}
function svndiff() {
local SVN_REV=0
local AGO_REV=0
# if [[ $@ =~ "-" ]]; then
if grep -q "-" <<< "$@"; then
SVN_REV=`svn info | grep Revision | awk -F ': ' ' { print $2 } '`
local REV_MINUS=`echo $@ | sed -e 's/\-//g'`
SVN_REV=`expr \( ${SVN_REV} \- ${REV_MINUS} + 1 \)`
AGO_REV=`expr \( ${SVN_REV} \- 1 \)`
svn log -r $SVN_REV
else
SVN_REV=`echo $@ | cut -d ":" -f2 -s`
AGO_REV=0
if [[ $SVN_REV = "" ]]; then
SVN_REV=$@
AGO_REV=`expr \( ${SVN_REV} \- 1 \)`
svn log -r $SVN_REV;
else
AGO_REV=`echo $@ | cut -d ":" -f1 -s`
AGO_REV=`expr \( ${AGO_REV} \- 1 \)`
fi
fi
svn diff -r$AGO_REV:$SVN_REV --summarize | sort;
}
# 관계가 없는 두 브랜치를 머지할 때 사용
# gitapplymacro "abcdefab..12345678" "main"
function gitapplymacro()
{
commit_between="$1"
apply_branch="$2"
git_diff_path="/tmp/gitapplymacro.diff"
rm -f "$git_diff_path"
# diff beetween a and b
git diff ${commit_between} > ${git_diff_path}
# checkout apply branch
git checkout ${apply_branch}
# apply diff
git apply --reject ${git_diff_path}
echo "\n"
echo "check /tmp/gitapplymacro.diff last content"
echo "\n\n" >> ${git_diff_path}
echo "========== reject file list ==========\n" >> ${git_diff_path}
# find merge conflict file
find . -name "*.rej" -type f >> ${git_diff_path}
echo "" >> ${git_diff_path}
}
# gitdiff <option> <commit>
# gitdiff --name-only 12345678
# gitdiff --name-only 12345678..abcdefab
function gitdiff() {
if [ $# -eq 0 ]; then
git diff
echo "================================================================"
git diff --cached
return 0
fi
# --name-only
local opts=( )
local commit="$@"
if [ $# -ge 2 ]; then
local array=( ${@} )
local opts=( $(echo "${array[@]:0:${#array[@]}-1}") )
commit=${@[-1]}
fi
if [ -z "$commit" ]; then
echo "commit argument is empty"
return 1
fi
# commits=$(echo "$commit" | tr ' ' '\n')
commits=$(echo "$commit" | sed 's/\.\./\n/')
commit_wcl=$(echo "$commits" | wc -l)
local head_commit=""
local tail_commit=""
if [ $commit_wcl -eq 1 ]; then
# local logs=$(git log --graph --date=format-local:"%Y-%m-%d %H:%M:%S" --pretty='%Cred%h%Creset %Cgreen(%ad)%Creset %C(bold blue)<%an>%Creset %C(auto)%d%Creset %n%s%n' -2 "$commit" )
local logs=$(git log --graph --date=iso-local --pretty='%Cred%h%Creset - %s %Cgreen(%ad)%C(auto)%d%Creset %C(bold blue)<%an>%Creset' -2 "$commit")
commits=$(echo "$logs" | awk -F ' ' '{ print $2 }')
head_commit=$(echo "$commits" | head -n 1)
tail_commit=$(echo "$commits" | tail -n 1)
elif [ $commit_wcl -eq 2 ]; then
# gitdiff "aaa..bbb"
head_commit=$(echo "$commits" | tail -n 1) # bbb
tail_commit=$(echo "$commits" | head -n 1) # aaa
else
echo "wrong diff hash argument (only 1 or 2)"
return 1
fi
if [ -z "$head_commit" ] || [ -z "$tail_commit" ]; then
echo "diff failed"
return 1
fi
echo "diff $tail_commit -> $head_commit (diff : $(git rev-list --count ${tail_commit}..${head_commit}))"
echo "\n"
git diff ${opts[@]} "${tail_commit}..${head_commit}"
}
# echo $SSH_CONNECTION
function vsdiff() { svn diff $@ | vi -; }
function sdfile() {
# svn diff | grep -E "\-\-\-\s.*(\(revision\s.*\)|\(nonexistent\))";
svn status | grep "^A" --color=never;
svn status | grep "^D" --color=never;
svn status | grep "^M" --color=never;
}
function svnconflict() {
if [ "$#" -ne 1 ]; then
echo "wrong argument"
fi
svn remove --force "$@"
svn resolve --accept=working "$@"
}
alias cc='clear'
function rmvimtmp() {
find . -name ".*.sw*" -type f -exec rm -rf {} \;
find . -name ".sw*" -type f -exec rm -rf {} \;
}
alias sendhttp='~/req.sh'
#memcheck
#ps -eo user,pid,ppid,rss,size,vsize,pmem,pcpu,time,comm --sort -rss | egrep "USER|health_check"
#ps -aeo user,pid,ppid,rss,size,vsize,pmem,pcpu,time,comm --sort -rss | egrep "USER|health_check"
#top -d 1 | egrep "PID|health_check"
# alias cme='fualias() { myname=`echo "$USER"`; sudo chown -R $myname:$myname $@ ; }; fuinit'
alias cme='fualias() { myname=`whoami`; sudo chown -R $myname $@ ; }; fuinit'
AGO_SFTP_DEBUG_PROCESS=""
function gdbs() {
[ -n "$(pidof gdbserver)" ] && pkill -f gdbserver
if [[ "$@" != "" ]]; then
if [[ "$@" = "httpgw" ]]; then
. ../.vscode/debugger.sh httpgw 0
# source ../.vscode/debugger.sh httpgw 0
fi
gdbserver :9091 ./"$@" &
AGO_SFTP_DEBUG_PROCESS="$@"
else
if [ -n "$AGO_SFTP_DEBUG_PROCESS" ]; then
if [[ "$AGO_SFTP_DEBUG_PROCESS" = "httpgw" ]]; then
. ../.vscode/debugger.sh httpgw 0
# source ../.vscode/debugger.sh httpgw 0
fi
gdbserver :9091 ./"$AGO_SFTP_DEBUG_PROCESS" &
else
echo "no argument"
fi
fi
}
alias kgdb='pkill -f gdbserver'
function cpdown() {
cp -r $@ ~/download/
}
alias colorpreview='for i in {0..255}; do print -Pn “%K{$i} %k%F{$i}${(l:3::0:)i}%f “ ${${(M)$((i%6)):#3}:+$’\\n’}; done'
alias sshclear='pkill -f "sshd:.*$USER.*\\@"'
alias sshclearall='pkill -f "sshd:.*\\@"'
function pytest() {
pytest $@;
if [ -d __pycache__ ]; then
rm -rf __pycache__/;
fi
if [ -d .pytest_cache ]; then
rm -rf .pytest_cache/;
fi
}
function splitlog() {
logpath=""
split_name=""
line=100000
if [ "$(command -v split)" = "" ]; then
echo "split command not exist"
return
fi
if [ $# -eq 0 ] || [ $# -gt 3 ];then
echo "wrong argument"
return
fi
if [ $# -eq 1 ]; then
logpath="$1"
split_name=$(basename "$logpath")
elif [ $# -eq 2 ]; then
line=$1
logpath="$2"
split_name=$(basename "$logpath")
elif [ $# -eq 3 ]; then
line=$1
logpath="$2"
split_name="$3"
fi
if [ ! -f "$logpath" ]; then
echo "file not exist"
return
fi
if [ -d "spdir_${split_name}" ]; then