This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mkshrc Mood Mod Project
1632 lines (1306 loc) · 41.9 KB
/
Mkshrc Mood Mod Project
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
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.88 2014/01/11 18:09:39 tg Exp $Android_mod by [email protected] 2014/08/04$
# ${ENV:=/system/etc/mkshrc}
# Patch 2.1 9 OCT 2022 by luisadha
#---Alias
alias lsxbin='ls /system/xbin/'
alias lsbinext='ls /system/bin/.ext'
alias lsbin='ls /system/bin/'
alias sysro='mount -o remount,ro /system' >/dev/null 2>&1;
alias sysrw='mount -o remount,rw /system' >/dev/null 2>&1;
alias microsd='cd $SECONDARY_STORAGE'
alias lrsaw='busybox ls -rSaw ${COLUMNS}';
alias his='history'
alias ...='cd ../../'
alias open='netstat -pan --inet'
alias xs='cd'
alias vf='cd'
alias moer='more'
alias moew='more'
alias acatenv='cat $ENV'
x=${KSH_VERSION#*KSH }; x=${x%% *};
if [ "$x" != "R50" ];
then
echo -e 'Warning: legacy devices but you can running with legacy mode,
please update your mksh binnary to R50 version later,
press "Enter" to iqnore. ';
read IGNORE
else
echo "$KSH_VERSION"
fi
# Simple SSHD & CONNECTBOT Environment
# /data/data/org.galexander.sshd/files
#---Modif environment
unset TERM
vendor="$(getprop ro.product.manufacturer)"
USER=${USER:-"user"}
LOGNAME=${LOGNAME:-"user"}
export HOME='/sdcard'
export BASH=$(whence -p bash)
export SHELL="${0}"
export ZSH=$(whence -p zsh)
export TERM='linux'
export VENDOR=$vendor
export SSH_CLIENT="${SSH_CLIENT}"
export SSH_TTY="${SSH_TTY}"
export BUSER=$(whoami)
#---Functions list
function setenv {
eval export "\"$1\""'="$2"'
}
function dropmask() {
unalias getprop
export SSH_CONNECTION=$(getprop ro.product.device);
}
function login () {
export USER=$(whoami)
}
function logout () {
login; dropmask;
}
#--HOSTNAME MUST = wlan0 for network
function notsecure {
HOSTNAME='localhost'
hname=$(busybox ifconfig wlan0 | awk '/inet / { print $2 }' | sed -e s/addr:// ); echo ${hname:- "${HOSTNAME}"};
}
export SSH_CONNECTION=${SSH_CONNECTION:-`notsecure`}
cu()
{
local program="$1"
local help="$*";
if [ -z "$program" ]; then echo "cu: Try \`cu --help' "; exit 1
elif [ "$program" == "--help" ]; then coreutils --help;
elif [ "$program" == "--version" ]; then coreutils --version;
else eval cmd=--coreutils-prog=$1; coreutils $cmd $help; fi
}
function extract() # Handy Extract Program (from Emmanuel Rouat bashrc)
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
function fe() { find . -type f -iname '*'"${1:-}"'*' \
-exec ${2:-file} {} \; ; }
# Creates an archive (*.tar.gz) from given directory.
function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
# Create a ZIP archive of a file or folder.
function makezip() { zip -r "${1%%/}.zip" "$1" ; }
# Make your directories and files access rights sane.
function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;}
function recordhabits() { printf "$(busybox ls /sdcard/.tmp | wc -l), times you opened a Terminal session" }
function mountfix()
{
# fixed mount not /proc/mounts generated by magisk
mount -o rw,remount /
mount -o bind /sbin/.magisk/mirror/system /system
mount -o rw,remount /system
}
#--SETUP ZSH's PROMPT
alias zsh=' unset TERM; setenv TERM xterm; $(whence -p zsh); ';
PPROMPT=$'%F{%(#.blue.green)}┌──(%B%F{%(#.red.blue)}%n%(#.💀%m).kali㉿kali)%b%F{%(#.blue.green)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.green)}]
└─%B%(#.%F{red}# .%F{blue}$% %b%F{reset} ';
RRPROMPT=$'%(?.. %? %F{red}%B!%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.) '
setenv PROMPT "$PPROMPT"
setenv RPROMPT "$RRPROMPT"
#---------------------#
case $KSH_VERSION {
(*MIRBSD\ KSH*R43*)
global NO_VAL_SUBS=1 ;;
(*MIRBSD\ KSH*)
global NO_VAL_SUBS=0
set -o inherit-xtrace \
+o pipefail ;;
(*) return 0 ;;
}
# fix for priviledge
[[ -o -p ]] || set +p
typeset -x FPATH BUSYBOX BB BBNDK TOOLBOX MKSH SHELL
FPATH=/system/etc/fpath
PATH=/vendor/bin:/system/vendor/bin:/system/bin:/system/bin/.ext:/system/xbin:/system/xbin/kern:/sbin:/sbin/bb
LD_LIBRARY_PATH=/vendor/lib:/system/vendor/lib:/system/lib:/system/lib/pkgconfig:/system/lib/python2.6/lib-dynload:/lib
export FPATH LD_LIBRARY_PATH PATH
#autoload sysrw sysro rootrw rootro sudo
autoload sudo
unset BB BUSYBOX BBNDK TOOLBOX
: ${BUSYBOX:=$(whence -p busybox)} ${BB:=$BUSYBOX}
: ${BBNDK:=$(whence -p busybox.ndk)} ${BBNDK:=$BB}
alias -x busybox="${BUSYBOX}"
alias -x bb="${BUSYBOX}"
: ${TOOLBOX:=$(whence -p toolbox)}
alias -x toolbox="${TOOLBOX:=$(whence -p toolbox)}"
alias -x tt="${TOOLBOX}"
unset MKSH SHELL MKSHS
: ${MKSH:=$(whence -p mksh)} ${SHELL:=$MKSH} ${MKSHS:=$(whence -p mkshs)} ${SHELL:=$MKSHS}
export TOOLBOX BUSYBOX BB BBNDK MKSH SHELL MKSHS
# 2nd-attempt execve shell
unset EXECSHELL; eval export "\"EXECSHELL\""'="${MKSH:+/system/bin/mksh}"'
unset TERM TERMINFO TERMPATH TERMINFO_DIRS
typeset -x FCEDIT EDITOR VISUAL ED VIM VI MC NANO HOME TERMINFO TERM TERMPATH TERMINFO_DIRS
#################
# editor env. setup
################# #################
: ${ED="$(whence -p ed)"}
: ${VIM:=$(whence -p vim)}
: ${VI:=$(whence -p vi)}
: ${MC:=$(whence -p mc)}
: ${NANO:=$(whence -p nano)}
export ED VI VIM MC NANO
[[ -z $BBNDK ]] && { alias ed=ed; unalias ed; alias -x ed="$BB"' ed';} \
|| \
{ alias ed=ed; unalias ed; alias -x ed="$BBNDK"' ed';}
[[ -z $VIM ]] && unset VIM || { alias vim=vim; unalias vim; alias -x vim="$VIM";}
[[ -z $MC ]] && unset MC || { alias mc=mc; unalias mc; alias -x mc="$MC";}
[[ -z $VIM ]] && unset VIM || { alias vim=vim; unalias vim; alias -x vim="ulimit -e 1 && $VIM";}
[[ -z $MC ]] && unset MC || { alias mc=mc; unalias mc; alias -x mc="ulimit -e 1 && $MC";}
[[ -z $NANO ]] && unset NANO || { alias nano=nano; unalias nano; alias -x nano="ulimit -e 1 && $NANO";}
[[ -z $BBNDK ]] && { alias vi=vi; unalias vi; alias -x vi="$BB"' vi';} \
|| \
{ alias vi=vi; unalias vi; alias -x vi="$BBNDK"' vi';}
export EDITOR="$ED"
: ${EDITOR:=$VIM} ${EDITOR:=$VI} ${EDITOR:=$NANO} ${EDITOR:=$MC}
: ${VISUAL:=${EDITOR:=$ED}} ${FCEDIT:=${EDITOR:=$ED}}
################# #################
#################
alias -x id=${ID:=$BBNDK id}
export RESOLV_HOST_CONF=/system/etc/resolv.conf
export FCEDIT VISUAL ID
#
# make tmp directory for Andy
#
mktmp3(){
[[ -e $TMPDIR ]] && [[ -w $TMPDIR ]] && return 0 || :
[[ -e /sdcard ]] || {
[[ -e /storage/emulated/0 ]] && ln -sf /storage/emulated/0 /sdcard
}
(( $USER_ID )) && {
export TMPDIR=/sdcard/.tmp/$RANDOM
mkdir -p $TMPDIR 2>/dev/null
} || :
(( $USER_ID )) || {
busybox mount -o rw,remount /
mkdir -p /tmp 2>/dev/null
busybox mount -o ro,remount /
busybox mount -t tmpfs -o rw /tmp /tmp
export TMPDIR=/tmp/$RANDOM
mkdir -p $TMPDIR 2>/dev/null
}
}
mktmp3
: ${MKSH:=$(whence -p mksh)}; \
\
case $- {
(*i*)
# limits
(( USER_ID )) || {
set +o restricted
set +o bgnice
#ulimit -e 1 # max-nice (0-40)
set +o bgnice
#ulimit -r 7 # lowest-highest ioprio (0-7)
}
{ ulimit -c 0; "$(whence -p busybox)" ionice -n 7 -c 2 -p $$; "$(whence -p busybox)" renice -13 -p $$; } >/dev/null 2>&1
set -o nolog +o verbose +o trackall +o errexit -o braceexpand
ulimit -e 1; \
PS4='[${EPOCHREALTIME:-}] '; PS1=$'\1\r'; \
(( ${NO_VAL_SUBS:-1} )) \
&& \
{
### ..(PS1) NO VALSUB.. ###
PS1+=$'\1\e[2;41;33m\1''$(local e=$?
(( e )) && print -n -- ${e}$'\''\1\e[0;7;2m\1'\''"|")'$'\1\e[0;7;2m\1''${ : ${USER:=$({ local x=\?; ulimit -c 0 && ulimit -e 1 && \
x="$($BBNDK id 2>/dev/null)"
x=${x#*\(}
x=${x%%\)*};} \
|| x=$USER_ID; print -n -- $x)}; print -n -- $USER_ID;}:${PWD:-?}>'$'\1\e[0m\1 '
} \
|| \
{
### ..(PS1) VALSUB.. ###
PS1+='${|
local e=$?
[[ -o -x ]] && set +x && global -x XTR_DBG=1 || global -x XTR_DBG=0
#export XTR_DBG
(( e )) && \
REPLY+=$'\''\1\e[0;30;43m\1'\''${e}$'\''\1\e[0m\1'\''$'\''\1\e[2;37;40m\1'\''"|"$'\''\1\e[0m\1'\'' && { global ERRNO ; eval export "\"ERRNO\""'\''="${e:-0}"'\'' ; } || :
REPLY+="$(if
[[ ${HOSTNAME:-android} = *([Aa]ndroid|localhost) ]];
then
print -n -- $'\''\1\e[0;40;2;36m\1'\''$USER$'\''\1\e[0m\1'\''
elif
( (( ${#HOSTNAME} > 13 )) || \
(( ${%HOSTNAME} > 13 )) )
then
print -n --''\1\e[0;33;40m${HOSTNAME:0:12}..\1\e[0m''
else
print -n -- "\e[0;33;40m${HOSTNAME:-?}\e[0m"
fi)"
REPLY+=\
$'\''\e[0;40;7;1;30m:\e[0m\1\e[0;40;2;36m\1'\''$SSH_CONNECTION$'\''\e[0;40;7;1;30m:\e[0m\1\e[0m\1'\''
# REPLY+=\
# $'\''\1\e[0;31;40m\1'\''":
# "$'\''\1\e[0m\1'\''
local d=${PWD:-?} p=~
[[ $p = ?(*/) ]] || d=${d/#$p/~}
local m=${%d} n p=\>
(( m > 0 )) || m=${#d}
(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} \
|| p=
# grey: 0;40;7;1;30 # 4;0;0;140 # ;01;3;47#
REPLY+=\
$'\''\1\e[2;37;40m\1'\''${p}$'\''\1\e[0;33;40m\1'\''${d}$'\''\1\e[0m\1'\''
REPLY+=${| REPLY=\
$'\''\1\e[0;40;7;1;30m\1'\''\%$'\''\1\e[0m\1'\''
(( USER_ID )) \
&& return 0 \
|| REPLY=\#
REPLY=\
$'\''\1\e[0;7;31;47m\1'\''${REPLY}$'\''\1\e[0m\1'\''
return 0
}
(( XTR_DBG )) && set -x
return ${e};} '
}
typeset -x CUR_WIDTH VIM VIMPATH
: ${MKSH:=$(whence -p mksh)}
: ${SHELL:=$MKSH}
# LD_LIBRARY_PATH=/system/ubin/lib:/lib:${LD_LIBRARY_PATH}:/system/usr/lib
PATH=/system/ubin:${PATH}:/bin:/system/usr/bin
: ${FPATH:=/system/etc/fpath}
: ${TELNET_PORT:-8080}
: ${COLUMNS:-51}
: ${BASH:=bash --rcfile /system/etc/bash/bashrc} && \
alias -x bash='bash --rcfile /system/etc/bash/bashrc'
: ${CUR_WIDTH:-141}
ulimit -c 0 && while :
do
# HOME && HISTORY
typeset -x HOME HISTFILE HISTSIZE
{ [[ -r /data/media ]] && (local testusr=/data/media/"$RANDOM" && touch "${testusr:-}" >/dev/null 2>&1 && rm "$testusr" >/dev/null 2>&1) && typeset -x HOME=/data/media
} || \
{ [[ -r /sdcard && -w /sdcard ]] && typeset -x HOME=/sdcard
} || \
{ [[ -r /storage/emulated/legacy ]] && typeset -x HOME=/storage/emulated/legacy
} || \
{ typeset -x HOME=/ ; } \
&& \
{ export HOME; touch ~/.mkshhist 2>/dev/null && chmod 0770 ~/.mkshhist* 2>/dev/null || break 1
}
export HISTSIZE=2700 HOME HISTFILE=~/.mkshhist
break 1
done
export MKSH BASH FPATH BASH
: ${VIMDIFF:=${VIM%/*}/vimdiff} ${VIMPATH:=$VIM} ${EX:=${VIM%/*}/ex} ${VIEW:=${VIM%/*}/view} ${VIEWDIFF:=${VIM%/*}/viewdiff}
: ${VIMRUNTIME:=/system/etc/vim}
unset TERMCAP # depr.
# MC_KEYMAP MCEdit MC_SKIN MC_COLOR_TABLE
: ${MC:=$(whence -p mc)} ${MCDIFF:=$(whence -p mcdiff)} ${MCDIFF:=$MC mcdiff}
: ${MC_DATADIR:=/system/etc/mc} ${MC_DATADIR:=/system/usr/share/mc} ${MC_DATADIR:=/sdcard}
: ${MC_TMPDIR:=${TMPDIR:-/sdcard}}
: ${LINKS:=$(whence -p links)}
export ED VI VIM VIMDIFF VIMPATH VIEWDIFF EX VIEW VIMRUNTIME MC MCDIFF MC_DATADIR LINKS
: ;;
(*)
set +u
### : ${LD_LIBRARY_PATH:=/system/ubin:${LD_LIBRARY_PATH}:/sbin}
### : ${PATH:=${PATH}:/system/ubin:/sbin:/system/usr/bin}
: ;;
}
## nsterm-c also perfect, cut+pste, enter, del
#
######## -----TERM--SCHEISSE----- ########
#
## "*c terms" perfect, xtermc, xtermc
: ${TERMINFO:=/system/etc/terminfo}
set -A TERMINFO_DIRS -- $($BBNDK find /system/etc/terminfo -depth -type d -regex '/system/etc/terminfo/.*')
: ${TERM=xtermc} ${TERMPATH=$(print -n -- ${TERMINFO@Q}"/${TERM:0:1}/"${TERM@Q})}
export TERMINFO TERM TERMPATH
: ${ADB:=/system/bin/adb}
: ${ADBD:=/sbin/adbd}
: ${FPATH:=/system/etc/fpath}
: ${USER:=$(ulimit -c 0 && { local x=\?; x="$($BBNDK id 2>/dev/null)"; x=${x#*=}; x=${x%%\ *};} \
|| \
{ x="$(ulimit -c 0 && $BBNDK id 2>/dev/null)"; x=${x#*\=}; x=${x%%\ g*};}; print -n -- $x)}
alias which=which; unalias which; \
alias -x which='whence -p'
set -U -o markdirs -o trackall
(( ${NO_VAL_SUBS:-1} )) || set -o inherit-xtrace
# Busybox Aliases
## off: cp
: ${BBNDK:=$(whence -p busybox.ndk)}
: ${BB:=$(whence -p busybox)}
export BBNDK BB
unset i && \
for i in ed vi catv pgrep pidof \
chmod chown mkdir mount umount mv rm rmdir renice ionice readlink touch insmod lsmod modinfo modprobe swapon swapoff mkswap rmmod hexdump df ln sync dd du od
do
{ [[ ! -z ${BBNDK:-} && -x $BBNDK ]] && \
{ alias ${i}=${i}; unalias ${i}; alias -x "${i}"="${BBNDK} ${i}";};} \
|| \
{ [[ -e /system/xbin/busybox && -x /system/xbin/busybox ]] && \
{ alias ${i}=${i}; unalias ${i}; alias -x "${i}"="/system/xbin/busybox ${i}";};} \
|| \
{ [[ ! -z ${BB:-} && -x $BB ]] && \
{ alias ${i}=${i}; unalias ${i}; alias -x "${i}"="${BB:=$(whence -p busybox)} ${i}";};}
done \
&& unset i
[[ ! -z ${BBNDK:=$(whence -p busybox.ndk)} ]] && \
{ alias fstrim=fstrim; unalias fstrim; alias -x "fstrim"="$(whence -p fstrim)";}
# toolbox aliases
# rm''d: hd od cat sleep insmod lsmod modinfo modprobe swapon swapoff mkswap rmmod top id df ps
: ${TOOLBOX:=$(whence -p toolbox)}
export TOOLBOX
unset i && \
for i in getprop
do
{ [[ -e /system/bin/toolbox && -x /system/bin/toolbox ]] && \
{ alias ${i}=${i}; unalias ${i}; alias -x "${i}"="/system/bin/toolbox ${i}";};} \
|| \
{ [[ ! -z ${TOOLBOX:-} && -x ${TOOLBOX:-} ]] && \
{ alias ${i}=${i}; unalias ${i}; alias -x "${i}"="$TOOLBOX ${i}";};}
done \
&& unset i
#alias echo=echo; unalias echo; unset echo; \
#alias -x echo='builtin echo'
alias cat=cat; unalias cat; unset cat; \
alias -x cat='builtin cat'
#
# set user id, run prog
#
typeset -x CHPST; \
: ${CHPST:=$(whence -p chpst)}; alias -x chpst="$CHPST"
typeset -fx suid; \
function suid {
local progy=
(( $# > 1 )) || progy='mksh'
"${SU:-$(whence -p su)}" --command exec "${SHELL:-/system/bin/mksh} -c "\""chpst -u $@ ${progy:-}"\"
}
# vanilla sudo
typeset -fx sudov; \
function sudov {
"${SU:-$(whence -p su)}" --shell "${MKSH:-$(whence -p mksh)}" -c exec "${SHELL:-/system/bin/mksh} -c "\""$@"\"
}
#
# pexec`'d sudo, pexec-su shell with no args
#
#
typeset -fx sudo; \
function sudo {
(( $# )) || set -- /system/bin/mksh
"$(whence -p pexec)" --shell /system/bin/mksh -c "/system/xbin/su --command '/system/bin/mksh -c '\''$@'\'"
}
alias -x psudo=sudo
alias xx=sudo
alias sx=sudo
alias doch='sudo $(fc -ln -1)'
alias dochja='sysrw; sudo $(fc -ln -1); (( $? )) || sync; sysro'
alias aberdochja='rootrw; sysrw; sudo $(fc -ln -1); (( $? )) || sync; sysro; rootro'
whence -p rot13 >/dev/null || alias rot13='tr \
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \
nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
#
# START OF STOCK MKSHRC FUNCTIONS
#
# ---------------- ---------------- ---------------- ---------------- --------------------------- ---------------- ---------------- ---------------
#-
# hd
function hd {
local -Uui16 -Z11 pos=0
local -Uui16 -Z5 hv=2147483647
local dasc line i
cat "$@" | { set +U; if read -arN -1 line; then
typeset -i1 line
i=0
while (( i < ${#line[*]} )); do
hv=${line[i++]}
if (( (pos & 15) == 0 )); then
(( pos )) && print -r -- "$dasc|"
print -n "${pos#16#} "
dasc=' |'
fi
print -n "${hv#16#} "
if (( (hv < 32) || (hv > 126) )); then
dasc+=.
else
dasc+=${line[i-1]#1#}
fi
(( (pos++ & 15) == 7 )) && print -n -- '- '
done
while (( pos & 15 )); do
print -n ' '
(( (pos++ & 15) == 7 )) && print -n -- '- '
done
(( hv == 2147483647 )) || print -r -- "$dasc|"
fi; }
}
# Berkeley C shell compatible dirs, popd, and pushd functions
# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
DIRSTACKBASE=$(realpath ~/. 2>/dev/null || print -nr -- "${HOME:-/}")
set -A DIRSTACK
function chpwd {
DIRSTACK[0]=$(realpath . 2>/dev/null || print -r -- "$PWD")
[[ $DIRSTACKBASE = ?(*/) ]] || \
DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/~}
:
}
chpwd .
function cd {
builtin cd "$@" || return $?
chpwd "$@"
}
function cd_csh {
local d t=${1/#~/$DIRSTACKBASE}
if ! d=$(builtin cd "$t" 2>&1); then
print -u2 "${1}: ${d##*cd: $t: }."
return 1
fi
cd "$t"
}
function dirs {
local d dwidth
local -i fl=0 fv=0 fn=0 cpos=0
while getopts ":lvn" d; do
case $d {
(l) fl=1 ;;
(v) fv=1 ;;
(n) fn=1 ;;
(*) print -u2 'Usage: dirs [-lvn].'
return 1 ;;
}
done
shift $((OPTIND - 1))
if (( $# > 0 )); then
print -u2 'Usage: dirs [-lvn].'
return 1
fi
if (( fv )); then
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
(( fl )) && d=${d/#~/$DIRSTACKBASE}
print -r -- "$fv $d"
let fv++
done
else
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
(( fl )) && d=${d/#~/$DIRSTACKBASE}
(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) ))
if (( fn && (cpos += dwidth + 1) >= 79 && \
dwidth < 80 )); then
print
(( cpos = dwidth + 1 ))
fi
print -nr -- "$d "
let fv++
done
print
fi
return 0
}
function popd {
local d fa
local -i n=1
while getopts ":0123456789lvn" d; do
case $d {
(l|v|n) fa+=" -$d" ;;
(+*) n=2
break ;;
(*) print -u2 'Usage: popd [-lvn] [+<n>].'
return 1 ;;
}
done
shift $((OPTIND - n))
n=0
if (( $# > 1 )); then
print -u2 popd: Too many arguments.
return 1
elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
print -u2 popd: Directory stack not that deep.
return 1
fi
elif [[ -n $1 ]]; then
print -u2 popd: Bad directory.
return 1
fi
if (( ${#DIRSTACK[*]} < 2 )); then
print -u2 popd: Directory stack empty.
return 1
fi
unset DIRSTACK[n]
set -A DIRSTACK -- "${DIRSTACK[@]}"
cd_csh "${DIRSTACK[0]}" || return 1
dirs $fa
}
function pushd {
local d fa
local -i n=1
while getopts ":0123456789lvn" d; do
case $d {
(l|v|n) fa+=" -$d" ;;
(+*) n=2
break ;;
(*) print -u2 'Usage: pushd [-lvn] [<dir>|+<n>].'
return 1 ;;
}
done
shift $((OPTIND - n))
if (( $# == 0 )); then
if (( ${#DIRSTACK[*]} < 2 )); then
print -u2 pushd: No other directory.
return 1
fi
d=${DIRSTACK[1]}
DIRSTACK[1]=${DIRSTACK[0]}
cd_csh "$d" || return 1
elif (( $# > 1 )); then
print -u2 pushd: Too many arguments.
return 1
elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
print -u2 pushd: Directory stack not that deep.
return 1
fi
while (( n-- )); do
d=${DIRSTACK[0]}
unset DIRSTACK[0]
set -A DIRSTACK -- "${DIRSTACK[@]}" "$d"
done
cd_csh "${DIRSTACK[0]}" || return 1
else
set -A DIRSTACK -- placeholder "${DIRSTACK[@]}"
cd_csh "$1" || return 1
fi
dirs $fa
}
# pager (not control character safe)
function smores {
local dummy line llen curlin=0
cat "$@" | while IFS= read -r line; do
llen=${%line}
(( llen == -1 )) && llen=${#line}
(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
if (( (curlin += llen) >= LINES )); then
print -n -- '\033[7m--more--\033[0m'
read -u1 dummy
[[ $dummy = [Qq]* ]] && return 0
curlin=$llen
fi
print -r -- "$line"
done
}
typeset -x PAGER='smores' MANPAGER='${PAGER}'
# base64 encoder and decoder, RFC compliant, NUL safe
function Lb64decode {
[[ -o utf8-mode ]]; local u=$?
set +U
local c s="$*" t=
[[ -n $s ]] || { s=$(cat; print x); s=${s%x}; }
local -i i=0 j=0 n=${#s} p=0 v x
local -i16 o
while (( i < n )); do
c=${s:(i++):1}
case $c {
(=) break ;;
([A-Z]) (( v = 1#$c - 65 )) ;;
([a-z]) (( v = 1#$c - 71 )) ;;
([0-9]) (( v = 1#$c + 4 )) ;;
(+) v=62 ;;
(/) v=63 ;;
(*) continue ;;
}
(( x = (x << 6) | v ))
case $((p++)) {
(0) continue ;;
(1) (( o = (x >> 4) & 255 )) ;;
(2) (( o = (x >> 2) & 255 )) ;;
(3) (( o = x & 255 ))
p=0
;;
}
t+=\\x${o#16#}
(( ++j & 4095 )) && continue
print -n $t
t=
done
print -n $t
(( u )) || set -U
}
set -A Lb64encode_code -- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /
function Lb64encode {
[[ -o utf8-mode ]]; local u=$?
set +U
local c s t
if (( $# )); then
read -raN-1 s <<<"$*"
unset s[${#s[*]}-1]
else
read -raN-1 s
fi
local -i i=0 n=${#s[*]} j v
while (( i < n )); do
(( v = s[i++] << 16 ))
(( j = i < n ? s[i++] : 0 ))
(( v |= j << 8 ))
(( j = i < n ? s[i++] : 0 ))
(( v |= j ))
t+=${Lb64encode_code[v >> 18]}${Lb64encode_code[v >> 12 & 63]}
c=${Lb64encode_code[v >> 6 & 63]}
if (( i <= n )); then
t+=$c${Lb64encode_code[v & 63]}
elif (( i == n + 1 )); then
t+=$c=
else
t+===
fi
if (( ${#t} == 76 || i >= n )); then
print $t
t=
fi
done
(( u )) || set -U
}
# Better Avalanche for the Jenkins Hash
typeset -Z11 -Uui16 Lbafh_v
function Lbafh_init {
Lbafh_v=0
}
function Lbafh_add {
[[ -o utf8-mode ]]; local u=$?
set +U
local s
if (( $# )); then
read -raN-1 s <<<"$*"
unset s[${#s[*]}-1]
else
read -raN-1 s
fi
local -i i=0 n=${#s[*]}
while (( i < n )); do
((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 ))
((# Lbafh_v ^= Lbafh_v >> 6 ))
done
(( u )) || set -U
}
function Lbafh_finish {
local -Ui t
((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \
((Lbafh_v << 1) & 0xFEFEFEFE) ))
((# Lbafh_v = t ^ (t >>> 8) ^ (Lbafh_v >>> 8) ^ \
(Lbafh_v >>> 16) ^ (Lbafh_v >>> 24) ))
:
}
# strip comments (and leading/trailing whitespace if IFS is set) from
# any file(s) given as argument, or stdin if none, and spew to stdout
function Lstripcom {
cat "$@" | { set -o noglob; while read _line; do
_line=${_line%%#*}
[[ -n $_line ]] && print -r -- $_line
done; }
}
# give MidnightBSD's laffer1 a bit of csh feeling
# setenv
export SHELL=${MKSH@Q} PAGER MANPAGER=PAGER MANWIDTH=45 LESSHISTFILE=-
alias cls='print -n \\033c'
#
#
# END OF STOCK MKSHRC FUNCTIONS
#
#
case $- {
(*)
:
;|
(!*i*)
:
set -o nolog
#set +o physical
#set -o trackall
#set +o allexport
set -o braceexpand
# set +o bgnice
#set +e
set +u -U
set +v +x
#+C +f +k
#set +h
;;&
(*i*)
:
#track cmds
set -h
set -m
# Curl link checks
(( USER_ID )) || (
ulimit -e 1 && ulimit -r 1
[[ -z $(whence -p curl) ]] || {
[[ -z /system/lib/libcurl.so.5.2.0 ]] || \
([[ -e /system/lib/libcurl.so.5 ]] || \
{ sysrw && ln -sn /system/lib/libcurl.so.5.2.0 /system/lib/libcurl.so.5 2>/dev/null;})
# libcrypto
[[ -z /system/lib/libcrypto.so ]] || \
([[ -e /system/lib/libcrypto.so.1.0.0 ]] || \
{ sysrw && ln -sn /system/lib/libcrypto.so /system/lib/libcrypto.so.1.0.0 2>/dev/null;})
# libssl
[[ -z /system/lib/libssl.so ]] || \
([[ -e /system/lib/libssl.so.1.0.0 ]] || \
{ sysrw && ln -sn /system/lib/libssl.so /system/lib/libssl.so.1.0.0 2>/dev/null;})
})
{ alias -x cdr='cd /'
## [[ -e /bin ]] && alias -x cdb='cd /bin' ||
alias -x cdb='cd /system/bin'
alias -x cdsb='cd /sbin'
[[ -e /lib ]] && alias -x cdl='cd /lib' || alias -x cdl='cd /system/lib'
alias -x cdsl='cd /system/lib'
alias -x cds='cd /system'
alias -x cdx='cd /system/xbin'
[[ -e /etc ]] && alias -x cde='cd /etc' || alias -x cde='cd /system/etc'
alias -x cdse='cd /system/etc'
alias -x cdf='cd /system/etc/fpath'
alias -x cdi='cd /system/etc/init.d'
alias -x cda='cd /system/app'
alias -x cdt="cd ${TMPDIR:-/tmp}"
[[ -e /usr ]] && alias -x cdu='cd /usr' || alias -x cdu='cd /system/usr'
alias -x cdsu='cd -L /system/usr'
alias -x cdsub='cd -L /system/usr/bin'
alias -x cdsusb='cd -L /system/usr/sbin'
alias -x cdsul='cd -L /system/usr/lib'
alias -x cdsus='cd -L /system/usr/share'
alias -x cdsrc='cd -L /system/usr/src'
alias -x cdd='cd /data'
alias -x cdda='cd /data/app'
alias -x cddd='cd /data/data'
alias -x cddm='cd /data/media'
alias -x cd0='cd /data/media/0'
alias -x cd1='cd -L /data/media/1'
alias -x cd00='cd /data/media/0/0'
alias -x cd4='cd /data/media/0/0/.4.4'
alias -x cd0='cd /data/media/0'
alias -x cd0dl='cd /data/media/0/Download'
alias -x cd0t='cd /data/media/0/tmp'
alias -x cdsd='cd -L /sdcard'
alias -x cdsdd='cd -L /sdcard/Download'
alias -x cddl='cd -L /sdcard/Download'
alias -x cdsdt='cd -L /sdcard/.tmp'
alias -x cdq='cd -P /system/ubin'
alias -x cddl='cd -L /sdcard/Download'
alias -x cdm='cd /data/media'
alias -x cdad='cd /sdcard/Android/data'
alias -x cdqq='cd -P /system/ubin'
alias -x cddlo='cd /data/local'
alias -x cdii='cd /system/etc/initx'
alias -x pgi='busybox.ndk ps -wlT | grep -i'
alias -x sc="${BUSYBOX}"' sync'
export GREP="$(whence -p grep)"
alias grep=grep; unalias grep; alias -x grep="${GREP}"' --color=auto'
alias -x gi='grep -ai'
alias -x ge='grep -aiE'
alias -x gf='grep -aiF'
alias -x egr='grep -E'
alias -x fgr='grep -F'
alias -x mg='busybox mount | grep'
alias -x lg='busybox ls -A | grep'
alias -x dg='busybox df | grep'
alias -x mkotg='otg'
alias -x hst="history -r"
alias -x hr="history -r"
typeset -fx findabtype; findabtype() {
find "$@" -depth -type s -o -type b -o -type p -o -type c -o -type l -print0 \
| 2>/dev/null xargs -0 -n 1 -- print -r --
}
alias tchm='toolbox chmod'; alias tcho='toolbox chown'
alias bchm='busybox chmod'; alias bcho='busybox chown'
alias tchn='tcho'; alias tchd='tchm'
alias bchn='bcho'; alias bchd='bchm'
alias -x str="$BB"' strings -an1'
alias -x lnsfn="$BB"' ln -sfn'
alias -x lnsf="$BB"' ln -sf'
alias -x urw='usrrw'
alias -x uro='usrro'
alias -x urs='usrrws'
alias -x trw='tmprw'
alias -x trs='tmprws'
alias -x drw='datrw'
alias -x drs='datrws'
alias -x smksh='/system/xbin/daemonsu --mount-master --daemon --shell /system/bin/mksh --command /system/bin/mksh -'
alias -x sush='smksh'
alias ss='su --mount-master'
#