-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliases
777 lines (659 loc) · 22.5 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
#
# shellcheck shell=dash
#
# A bunch of trash mostly
#
_UNAME=$(uname)
if uname -o >/dev/null 2>&1; then
_UNAME_O=$(uname -o)
fi
ID_SHELL () {
local _shname
_shname=''
if ! {
[ "${_UNAME}" = 'DragonFly' ] || [ "${_UNAME}" = 'OpenBSD' ] || \
[ "${_UNAME_O}" = 'Cygwin' ] || [ "${_UNAME_O}" = 'Msys' ]
}; then
_shname="$(basename -- "$(ps -o comm= $$)")"
elif [ "$IS_ZSH" = 'true' ]; then
_shname='zsh'
else
_shname='OTHER'
fi
printf "%s" "${_shname}"
unset _shname
}
Exists() {
command -v "$1" >/dev/null 2>&1
return $?
}
__get_base_name() {
ret=$(echo "$1" | sed -E "s/[^=]*=['\"]?\\?([[:alnum:][:punct:]/]*).*['\"]?/\\1/")
if echo "$ret" | grep -q '^\\'; then
ret=$(echo "$ret" | sed -E 's/^\\//')
fi
echo "$ret"
unset ret
}
# -g -> Soft global alias - add global flag if shell is zsh.
# -G -> Hard global alias - same as above but don't make alias at all unless zsh.
# -s -> Soft sudo - add sudo if not root.
# -S -> Hard sudo - add sudo if not root, and don't make alias otherwise.
# -t -> Test program - only make alias if the given command exists.
# -T -> Better test - only make alias if its base command exists.
# -e -> Escape - escape the command in the alias (eg. alias ll='\ls -l')
mkalias () {
local arg_1 alias_cmd alias_cmd_tmp do_sudo do_test do_alt do_global escape TEMP
OPTIND=1 # For some incomprehensible reason bash doesn't reset OPTIND by default.
do_sudo=false do_test=false do_alt=false do_global=false escape=false
while getopts 'gGsSt:TAe' ARG "$@"; do
case "$ARG" in
g)
[ "$(ID_SHELL)" = 'zsh' ] && do_global=true
;;
G)
[ "$(ID_SHELL)" = 'zsh' ] || return 1
do_global=true
;;
S)
if [ "$(id -u)" -ne 0 ]; then
do_sudo=true
else
return 1
fi
;;
s) [ "$(id -u)" -ne 0 ] && do_sudo=true ;;
t) command -v "$OPTARG" >/dev/null 2>&1 || return 1 ;;
T) do_test=true ;;
A) do_alt=true ;;
e) escape=true;;
*) echo 'Invalid arg -> '"'$ARG'" >&2 ; return 1 ;;
esac
done
shift $((OPTIND - 1))
if $do_alt; then
arg_1="${1}"
shift
for param in "$@"; do
TEMP=$(echo "$param" | sed -E 's/([[:alnum:][:punct:]]*).*/\1/')
if echo "$TEMP" | grep -q '^\\'; then
TEMP=$(echo "$TEMP" | sed 's/^\\//')
fi
if Exists "$TEMP"; then
alias_cmd_tmp="${arg_1}=${param}"
break
fi
done
[ "${alias_cmd_tmp}" ] || return 2
elif $do_test; then
TEMP=$(echo "$1" | sed -E "s/[^=]*=['\"]?([[:alnum:][:punct:]/]*).*['\"]?/\\1/")
if echo "$TEMP" | grep -q '^\\'; then
TEMP=$(echo "$TEMP" | sed -E 's/^\\//')
fi
Exists "$TEMP" || return 1
alias_cmd_tmp=$1
else
alias_cmd_tmp=$1
fi
if $escape; then
if $do_sudo && Exists 'sudo'; then
alias_cmd=$(echo "$alias_cmd_tmp" | sed 's/\([^=]*=\)\(.*\)/\1sudo \\\2/')
else
alias_cmd=$(echo "$alias_cmd_tmp" | sed 's/\([^=]*=\)\(.*\)/\1\\\2/')
fi
elif $do_sudo && Exists 'sudo'; then
alias_cmd=$(echo "$alias_cmd_tmp" | sed 's/\([^=]*=\)\(.*\)/\1sudo \2/')
else
alias_cmd=$alias_cmd_tmp
fi
if $do_global; then
eval "alias -g \"$alias_cmd\""
else
eval "alias \"$alias_cmd\""
fi
}
#---------------------------------------------------------
# ls aliases
#---------------------------------------------------------
MOARINFO='true'
if Exists 'exa'; then
alias exa='exa --group-directories-first'
alias ls='exa'
alias la='exa -a'
alias ll='exa -l'
alias lla='exa -l -a'
alias lst='exa -T'
alias llt='exa -T'
alias gls="LC_ALL=C ${__LS_:-ls} -B -H --color --group-directories-first"
# alias lls='exa -lrs size'
lls () {
local arg legal_opts
arg=''
if [ $# -eq 0 ]; then
arg='-s date'
elif ! { printf '%s' "$1" | \grep -q '^-'; }; then
if ! [ -e "$1" ]; then
arg="-s $1"
shift
else
arg='-s date'
fi
elif [ $# -ge 1 ] && [ "$1" = '-r' ] && ! { echo "$2" | \grep -q '^-'; }; then
arg="-rs date"
else
legal_opts='rSsDdeta'
OPTIND=1
while getopts "$legal_opts" OPT; do
case "$OPT" in
(s) arg="${arg} -s size" ;;
(S) arg="${arg} -rs size" ;;
(d) arg="${arg} -s date" ;;
(D) arg="${arg} -rs date" ;;
(r) arg="-r ${arg}" ;;
(e) arg="${arg} -s extension" ;;
(t) arg="${arg} -s type" ;;
(a) arg="${arg} -a" ;;
(*)
echo "lls: legal args \"$legal_opts\"" >&2
return 1
;;
esac
done
shift $((OPTIND - 1))
fi
eval "ls -l $arg"' "$@"'
}
EXA_COLORS=\
'gu=0;33:uu=0;33:da=0:rs=0:di=1;34:ln=1;36:mh=0:pi=40;33:so=1;35:do=1;35:bd=40;33;1:cd=40;33;1'\
':or=1;05;37;41:mi=1;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=1;32:*.tar=1;31:*.tgz=1;31:*.arc=1;31:'\
'*.arj=1;31:*.taz=1;31:*.lha=1;31:*.lz4=1;31:*.lzh=1;31:*.lzma=1;31:*.tlz=1;31:*.txz=1;31:*.tzo=1;31:*.t7z=1;31:*.zip=1;31:'\
'*.z=1;31:*.Z=1;31:*.dz=1;31:*.gz=1;31:*.lrz=1;31:*.lz=1;31:*.lzo=1;31:*.xz=1;31:*.zst=1;31:*.tzst=1;31:'\
'*.bz2=1;31:*.bz=1;31:*.tbz=1;31:*.tbz2=1;31:*.tz=1;31:*.deb=1;31:*.rpm=1;31:*.jar=1;31:*.war=1;31:*.ear=1;31:'\
'*.sar=1;31:*.rar=1;31:*.alz=1;31:*.ace=1;31:*.zoo=1;31:*.cpio=1;31:*.7z=1;31:*.rz=1;31:*.cab=1;31:*.wim=1;31:*.swm=1;31:'\
'*.dwm=1;31:*.esd=1;31:*.jpg=1;35:*.jpeg=1;35:*.mjpg=1;35:*.mjpeg=1;35:*.gif=1;35:*.bmp=1;35:*.pbm=1;35:*.pgm=1;35:'\
'*.ppm=1;35:*.tga=1;35:*.xbm=1;35:*.xpm=1;35:*.tif=1;35:*.tiff=1;35:*.png=1;35:*.svg=1;35:*.svgz=1;35:*.mng=1;35:'\
'*.pcx=1;35:*.mov=1;35:*.mpg=1;35:*.mpeg=1;35:*.m2v=1;35:*.mkv=1;35:*.webm=1;35:*.ogm=1;35:*.mp4=1;35:*.m4v=1;35:*.mp4v=1;'\
'35:*.vob=1;35:*.qt=1;35:*.nuv=1;35:*.wmv=1;35:*.asf=1;35:*.rm=1;35:*.rmvb=1;35:*.flc=1;35:*.avi=1;35:*.fli=1;35:'\
'*.flv=1;35:*.gl=1;35:*.dl=1;35:*.xcf=1;35:*.xwd=1;35:*.yuv=1;35:*.cgm=1;35:*.emf=1;35:*.ogv=1;35:*.ogx=1;35:*.cfg=0;'\
'32:*.conf=0;32:*.diff=0;32:*.doc=0;32:*.ini=0;32:*.log=0;32:*.patch=0;32:*.pdf=0;32:*.ps=0;32:*.tex=0;32:'\
'*.txt=0;32:*.aac=0;36:*.au=0;36:*.flac=0;36:*.m4a=0;36:*.mid=0;36:*.midi=0;36:*.mka=0;36:*.mp3=0;36:*.mpc=0;36:'\
'*.ogg=0;36:*.ra=0;36:*.wav=0;36:*.oga=0;36:*.opus=0;36:*.spx=0;36:*.xspf=0;36:*.zpaq=1;31'
export EXA_COLORS
else
_super_basic=false
case "${_UNAME}" in
OpenBSD | FreeBSD | DragonFly)
if Exists 'gls'; then
__LS_='gls'
else
_super_basic=true
fi
;;
esac
if ${_super_basic}; then
alias ls='ls -F'
alias la='ls -A'
alias ll='ls -lh'
alias lla='ls -lhA'
else
# Aliases based on the standard ls will hide backups.
alias ls="LC_ALL=C ${__LS_:-ls} -B -H --color --group-directories-first"
unset __LS_
if [ "$SSH_CONNECTION" ] || [ "$SSH_CLIENT" ] || [ "$MOARINFO" ]; then
alias ll='ls -l -h'
alias lll='ls -go -h'
else
alias ll='ls -go -h'
alias lll='ls -l -h'
fi
alias la='ls -A'
alias lla='ll -A -h'
alias laa='lll -A -h'
alias llt='ll -t'
alias lat='ll -At'
# I don't remember why these even exist.
alias LS='LC_ALL=C \ls -H --group-directories-first'
alias l='LS -CF --color'
alias llb='l -l -h'
alias lab='la -l -h'
# Some extras
alias Ll='ll -L'
alias Lla='lla -L'
alias Ls='ls -L'
fi
fi
# ---------------------------------------------------------
# grep with color, from default bashrc.
if [ "x${_UNAME}" != 'xOpenBSD' ]; then
alias grep='\grep --colour=auto'
alias fgrep='\fgrep --color=auto'
alias egrep='\egrep --color=auto'
fi
# Pretty basic.
mkalias -A 'cd' 'smartcd -P' 'cd -P'
mkalias -s dus='du -sh'
alias whack='pkill -9'
alias chpx='chmod +x'
alias chmx='chmod -x'
alias info='info --vi-keys'
alias du='du -h'
alias du1='du -d1'
alias df='df -h'
alias ln='ln -s'
alias dmesg='dmesg --color=always'
alias dmesgl='dmesg | \less -r'
alias suvi='sudoedit'
alias free='free -wh'
alias od='command od -Ax -w32'
# God I am lazy
mkalias -A 'CO' '/usr/libexec/cw/configure' './configure'
alias CH='./configure --help'
alias CMK='mkdir build && cd build'
mkalias -T pkgconfig='pkg-config'
# Yet more git aliases.
mkalias -T gcred='git config credential.helper store'
mkalias -T gits='git status'
alias glgs="git log --graph --pretty=\"%C()\${(l.\$((\${COLUMNS}-8))..─.)}\"'%n%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all --summary --shortstat"
alias glgsa="git log --graph --pretty=\"%C()\${(l.\$((\${COLUMNS}-8))..─.)}\"'%n%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all --summary --stat"
# The rest.
mkalias -Tg clformat='clang-format'
mkalias -T cdif='colordiff'
mkalias -T pylint='pylint -f colorized'
mkalias -T pylint2='pylint2 -f colorized'
mkalias -T pylint3='pylint3 -f colorized'
mkalias -T sage='sage -q'
mkalias -T ari='aria2c'
mkalias -T par='par-format'
mkalias -Ts zef='/usr/share/perl6/site/bin/zef'
mkalias -S parted='parted'
mkalias -T rg='rg -S'
mkalias -T dwdiff='dwdiff --color'
alias diff='diff --color -u'
alias winetricks='winetricks -q'
mkalias -T wolf='wolframscript'
# Bat
BAT_COMMON="--color=always --pager='less -LR'"
mkalias -eT bat="bat $BAT_COMMON --paging=always"
mkalias -eT batl="bat $BAT_COMMON --paging=always --language"
mkalias -eT batp="bat $BAT_COMMON --paging=never"
mkalias -eT batlp="bat $BAT_COMMON --paging=never --language"
unset BAT_COMMON
# Force less to take raw characters (color).
[ "$LESS" ] || alias less='less -r'
if [ "$SYSID" = 'laptop-gentoo' ]; then
alias emerge='emerge -k'
fi
case "$SYSID" in
'gentoo'|'laptop-gentoo')
mkalias -T qs='qsearch'
mkalias -S emr="emerge"
mkalias -s emp="emerge --pretend"
mkalias -s ema="emerge --ask"
mkalias -s em1="emerge --ask --oneshot"
mkalias -s empd="emerge --pretend --verbose --deep --depclean"
mkalias -s emupdate="emerge -aDNuv -j6 --keep-going --backtrack=100 --with-bdeps=y @world"
mkalias emi="emerge --info"
# mkalias -s emupdate="emerge -aDNu --keep-going @world -j6"
# mkalias -s emupdate="emerge --ask --update --deep --newuse --with-bdeps=y --keep-going @world --exclude \"chromium\""
# mkalias -s emupdateP="emerge --pretend --update --deep --newuse --with-bdeps=y @world"
# mkalias -s emupdateF="emerge --update --deep --newuse --with-bdeps=y --keep-going @world"
mkalias -TS ufed='ufed'
mkalias -T repm='repoman manifest'
alias watchfetch='tail -f /var/log/emerge-fetch.log'
# mkalias -A 'gvi' 'nvim-gtk --' 'nvim-qt'
if Exists esearch; then
alias ems='esearch'
alias emss='esearch -S'
alias emc='esearch -c'
alias emcs='esearch -c -S'
Ems() {
local key desc both
desc=false both=true key='3'
OPTIND=1
while getopts "k:sSb" ARG; do
case "$ARG" in
(S) desc=true ;;
(b) both=$(if $both; then echo 'false'; else echo 'true'; fi) ;;
(k|s)
if [ "$OPTARG" -lt 3 ]; then
key=$((OPTARG + 2))
# ((key=OPTARG + 2))
else
key="$OPTARG"
fi
;;
(-*)
echo "Invalid option '${1}'" >&2 ;
exit 1 ;
;;
esac
done
shift $((OPTIND - 1))
[ $# -ge 1 ] || { echo 'No args' >&2; return 3; }
{
if $both; then
esearch -c "$@"
esearch -c -S "$@";
elif $desc; then
esearch -c -S "$@";
else
esearch -c "$@"
fi
} | sort -u "-k${key}" | \
perl -pE 's{\033\[01m([^/]+?)/([^\033]+?)\033\[39;49;00m (\(.*?\)): }{ \033[0;36m$1\033[0m ` \033[0;33m$2\033[0m ` }' | \
column -t -s'`' -o' '
}
else
alias ems='emerge --search'
fi
unset EMERGE
;;
esac
# Linux Aliases
case "${_UNAME}" in
Linux)
if Exists 'pacman'; then
mkalias -s pacman='pacman --color=always'
mkalias -s pacs='\pacman --color=always -S --needed'
mkalias -s pacup='\pacman --color=always -Syu'
alias pacss='\pacman --color=always -Ss'
alias paci='\pacman --color=always -Si'
alias pac='\pacman --color=always'
fi
mkalias -T pacaur='pacaur --color=always'
mkalias -T pacg='pacget -s'
mkalias -T yays='yay -S'
mkalias -T yayss='yay -Ss'
mkalias -T yayi='yay -Si'
mkalias -s stl='systemctl'
mkalias -T n.='nemo . >/dev/null 2>&1 &'
mkalias -T e.='nemo . >/dev/null 2>&1 &'
mkalias -T d.='dolphin . >/dev/null 2>&1 &'
mkalias -TS ualt='update-alternatives'
if Exists 'apt'; then
mkalias -S apt='apt'
alias apts='command apt search'
if Exists 'apt-fast'; then
mkalias -s aptf='apt-fast'
mkalias -s aptfi='apt-fast install'
else
mkalias -s apti='apt install'
fi
fi
alias make="make --no-print-directory -O -j\"$(nproc)\""
;;
FreeBSD | DragonFly)
mkalias -S pkg='pkg'
mkalias -T pf='portfind'
mkalias -s pki='pkg install'
mkalias -s mic='make install clean'
mkalias -s mc='make config'
mkalias -s mcr='make config-recursive'
alias pks='\pkg search'
alias pkgf='\pkg query %Fp'
;;
esac
#Exists 'gcp' && ! [ "$(command -v gcp)" = '/usr/bin/gcp' ] && unalias gcp
if [ "$IS_CYGWIN" ]; then
mkalias -T apt='apt-cyg'
mkalias -T pacman='pac-cyg --color=always'
fi
if [ "$IS_WINDOWS" ]; then
alias 'e.'='explorer .'
alias vi=''
unalias vi
if Exists 'pacman'; then
alias pacs='pacman -S --color=always'
alias pacss='pacman -Ss --color=always'
alias paci='pacman -Si --color=always'
fi
else
Exists 'nvim-qt' &&
gvi() {
if [ $# -eq 0 ]; then
nvim-qt --maximized 2>/dev/null
else
nvim-qt --maximized -- "$@" 2>/dev/null
fi
}
fi
if [ ".$TERM" = '.linux' ]; then
mkalias -T vi='vim'
fi
# ----------------------------------------------------------
# Misc
alias valgrindall='valgrind -v --show-below-main=yes --leak-check=full --expensive-definedness-checks=yes \
--read-inline-info=yes --read-var-info=yes --num-callers=30 --vex-iropt-level=2 \
--px-default=allregs-at-each-insn --px-file-backed=allregs-at-each-insn --vex-iropt-unroll-thresh=400 --vex-guest-max-insns=100 \
--track-origins=no --trace-children=no --show-leak-kinds=all \
'
# ----------------------------------------------------------
# Functions
Exists 'git' && {
gitc() {
local usage github deep recurse cmd opts
usage="Usage: $0 [-gdsr] repo [dest]"
opts='gdsr'
if [ $# -eq 0 ]; then echo "$usage"; return 1; fi
OPTIND=1
while getopts "$opts" ARG; do
case "$ARG" in
s) deep='' ;;
d) deep='YES' ;;
g) github='YES' ;;
r) recurse='YES' ;;
\?) echo "$usage" >&2
return 2 ;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then echo "$usage"; return 1; fi
cmd='git clone'
[ "$deep" ] || cmd="$cmd --depth 1"
[ "$recurse" ] && cmd="$cmd --recursive"
if [ "$github" ]; then cmd="$cmd https://github.com/$1"; shift; fi
cmd="$cmd "'"$@"'
eval $cmd
}
}
perlman () {
# [ $# -ge 1 ] || return 1
# perldoc -T "$@" >/dev/null || return 2
perldoc -T -onroff "$@" | man -l -
}
if [ "${_UNAME}" = 'DragonFly' ] || [ "${_UNAME}" = 'FreeBSD' ]; then
Exists 'gfind' && FIND='gfind'
else
FIND='find'
fi
[ "$FIND" ] && \
ifind() {
if [ $# -eq 1 ]; then
find . -iname '*'"$1"'*'
elif [ $# -eq 2 ]; then
find "$1" -iname '*'"$2"'*'
else
echo "USAGE: $0 [dir] (EXPR)"
echo "Directory is optional."
fi
}
lessinfo() {
if [ "$#" -eq 0 ]; then
echo "No page supplied"
return 1
fi
info --subnodes -o - "$1" | less
}
Exists 'eovim' && {
eov() {
(
NoExtChars='True'; export NoExtChars
eovim -g '125x55' "$@" > /dev/null 2>&1 &
)
}
}
Exists 'fzf' && {
cdfzf() {
cd "$(dirname "$(fzf "$@")")" || return 1
}
}
[ "$IS_CYGWIN" ] && {
tab() {
mintty.exe -i /Cygwin.ico -e /bin/xhere /bin/bash.exe
}
}
Exists 'J7Z.sh' && {
j7z() {
J7Z.sh "$@" >/dev/null 2>&1 &
}
}
if Exists 'fzy'; then
ffzy() {
local _fzlen_ _cd_ _cmd_ _smartness_ _extra_ _statement_ __opts
_fzlen_=30
_cd_=false
_cmd_='find'
__opts='hdcl:rgu:S:'
if Exists 'fd'; then
_cmd_='fd'
_extra_='-a'
fi
OPTIND=1
while getopts "$__opts" ARG; do
case "$ARG" in
c) _cd_=true ;;
l) _fzlen_=$OPTARG ;;
f)
_cmd_='find'
_extra_=''
;;
d)
_cmd_='fd'
_extra_='-a'
;;
r)
_cmd_='rg'
_extra_='--files'
;;
g)
_cmd_='ag'
_extra_='-g ""'
;;
u)
case "$_cmd_" in
'rg')
case "$OPTARG" in
0) _smartness_= ;;
1) _smartness_='-u' ;;
2) _smartness_='-uu' ;;
3) _smartness_='-uuu' ;;
*) echo 'rg "u" option must be between 0 and 3 (inclusive).' >&2 ;;
esac ;;
'ag')
case "$OPTARG" in
0) _smartness_= ;;
1) _smartness_='--hidden' ;;
2) _smartness_='--all-types' ;;
3) _smartness_='-u' ;;
*) echo 'ag "u" option must be between 0 and 3 (inclusive).' >&2 ;;
esac ;;
esac
;;
h)
cat <<-"EOF" >&2
Wrapper for fzy. Options: "${__opts}"
-r: rg, -g: ag, -f: find, -d: fd
-l: set fzy length
-n -> no hidden files (fd only)
-u N -> smartness level (0 to 3, ag and rg only)
EOF
return 0
;;
S) _smartness_="$OPTARG" ;;
*) echo 'Fatal, exiting.' >&2 ;;
esac
done
shift $((OPTIND - 1))
if [ -z "$_smartness_" ]; then
if [ ".${_cmd_}" = '.rg' ]; then
_smartness_='-uuu'
elif [ ".${_cmd_}" = '.ag' ]; then
_smartness_='-u'
fi
fi
_statement_="\"${_cmd_}\" ${_smartness_} ${_extra_} \"${1:-.}\" 2>/dev/null | fzy -l\"${_fzlen_}\""
if ${_cd_}; then
local __file__
__file__=$( (set -o shwordsplit >/dev/null 2>&1) && set -o shwordsplit
eval "$_statement_")
echo "$__file__"
if [ -d "$__file__" ]; then
cd "$__file__" || return 1
else
cd "$(dirname "$__file__")" || return 1
fi
else
eval "$_statement_"
fi
}
cdf() {
ffzy -c "$@"
}
fi
cppMacroOnly() { (
(set -o shwordsplit >/dev/null 2>&1) && set -o shwordsplit
[ $# -eq 0 ] && exit 1;
[ $# -eq 1 ] && __file="$1" && __CPP='clang' && __ARGS='-E -P -'
[ $# -gt 1 ] && __file="$1" && shift && __CPP="$1" && shift && __ARGS=$*
perl -pe 's/^#include.*\n//g' "$__file" | $__CPP $__ARGS
) }
goinstallsub() {
local testrun basedir
OPTIND=1
testrun=false
basedir='../../roflcopter4'
while getopts 'nd:' ARG "$@"; do
case "$ARG" in
n) testrun=true ;;
d) basedir="$OPTARG" ;;
*) echo 'Invalid arg -> '"'$ARG'" >&2 ; return 1 ;;
esac
done
shift $((OPTIND - 1))
if ! [ -d "$basedir" ]; then
echo "Invalid base directory \`$basedir'" >&2
return 1
fi
for f in $(find "$basedir" -type d -path "*/$(basename "$(pwd)")/*" | \
sed 's|^\(\.\./\)*||')
do
if [ "$(find "../../$f" -name '*.go')" ]; then
if [ $# -gt 0 ]; then
echo "go install" "$@" "$f"
else
echo "go install $f"
fi
if ! $testrun; then
go install "$@" "$f"
fi
fi
done
}
if Exists 'emacs'; then
emacs() {
command emacs --maximized "$@" >/dev/null 2>&1 &
}
fi
case "$SYSID" in
'gentoo'|'gentoo-laptop')
etcp() {
cd /etc/portage || return 1
}
wut() {
{ [ $# -eq 1 ] && [ -d "$1" ]; } || return 1
ag --nofilename 'DESCRIPTION=' "${1}/" | sort -u | perl -pe 's/^\n//'
}
;;
esac
unset TEMP alias_cmd do_global do_test do_sudo
# vim: tw=0 sw=4 sts=4 ts=8 ft=sh