forked from AdrianDC/advanced_development_shell_tools
/
android_functions.rc
executable file
·1001 lines (927 loc) · 31 KB
/
android_functions.rc
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/bash
# ======================================
# Developed by Adrian DC - 2015-2016
# ======================================
# === Repo shortcuts ===
function reposypb()
{
repo forall -c 'echo "Syncing project ${REPO_PROJECT}"; \
while true; do \
timeout 15 repo sync -j1 --current-branch --detach -f --force-broken --force-sync -c --no-clone-bundle --no-tags .; \
if [ $? -eq 0 ]; then \
echo "";
echo " Project ${REPO_PROJECT} : Fallback to old branch"; \
git fetch --quiet ${REPO_REMOTE} cm-13.0; \
git reset --hard FETCH_HEAD; \
break;
fi; \
done;';
}
function reposyp()
{
repo forall -c 'echo "Syncing project ${REPO_PROJECT}"; \
while true; do \
timeout 15 repo sync -j1 --current-branch --detach -f --force-broken --force-sync -c --no-clone-bundle --no-tags .; \
if [ $? -eq 0 ]; then break; fi; \
done;';
}
alias repolx='nano .repo/local_manifests/updates.sh; .repo/local_manifests/updates.sh';
alias repop='repopick';
function reposyl()
{
local currentdir=${PWD}; repor;
if [ ! -z "$1" ] && [ -d "$1" ] && [ ! -z "$2" ] && [ -d "$2" ]; then
cd "./$1";
git fetch "$2/$1";
reposy .;
fi;
cd "$currentdir";
}
function repounshallow()
{
repo forall -c 'gitbranch=${REPO_RREV##*/}; \
echo ""; echo "Unshallowing project ${REPO_PROJECT} [${REPO_REMOTE}/${gitbranch}]"; \
git fetch --unshallow ${REPO_REMOTE};';
}
function repothis()
{
export currentdir=${PWD};
repo forall -c ' \
if [ "$currentdir" = "$(pwd)" ]; then \
echo " Current project: ${REPO_PROJECT} [${REPO_REMOTE}/${REPO_RREV##*/}]"; \
fi;';
}
function repoupdate()
{
repo --version;
echo "";
if [ ! -d ~/bin ]; then mkdir ~/bin; fi;
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo;
chmod a+x ~/bin/repo;
echo "";
repo --version;
}
function .repoupdate()
{
cd .repo/repo/;
git log --pretty=oneline -10;
echo "";
git fetch origin stable;
git reset --hard origin/stable;
echo "";
git branch -vv;
echo "";
git log --pretty=oneline -10;
cd ../../;
}
# === Android builds ===
function makesep()
{
cwd=$(pwd);
repor;
if [ -d ./system/sepolicy ]; then
mmm -B -j$(grep -c ^processor /proc/cpuinfo) ./system/sepolicy/ | tee $LogFile;
else
mmm -B -j$(grep -c ^processor /proc/cpuinfo) ./external/sepolicy/ | tee $LogFile;
fi;
cd $cwd;
}
function makedefconf()
{
export ARCH=arm;
export SUBARCH=arm;
export KCONFIG_NOTIMESTAMP=true;
DEFCONFIG_PATH=./arch/arm/configs;
if [ ! -z "$1" ] && [ -f "$DEFCONFIG_PATH/"*"$1"* ]; then
DEFCONFIG_FILE=$(basename "$DEFCONFIG_PATH/"*"$1"*);
else
DEFCONFIG_FILE="cm_viskan_huashan_defconfig";
fi;
if [[ "$1" == "google" ]]; then
./scripts/kconfig/merge_config.sh ${DEFCONFIG_PATH}/${DEFCONFIG_FILE} android/configs/android-base.cfg android/configs/android-recommended.cfg
mv ./.config ./.config_android;
make ${DEFCONFIG_FILE};
meld ./.config ./.config_android;
rm ./.config_android;
elif [ ! -z "$1" ] && [ ! -f "$DEFCONFIG_PATH/"*"$1"* ] || [ ! -z "$2" ]; then
make ${DEFCONFIG_FILE};
meld ./.config ${DEFCONFIG_PATH}/${DEFCONFIG_FILE};
else
make ${DEFCONFIG_FILE}
make menuconfig;
make savedefconfig;
meld ./defconfig ${DEFCONFIG_PATH}/${DEFCONFIG_FILE};
rm ./defconfig;
fi;
make mrproper;
}
function mmmall() { mmm $1 $(find -maxdepth 3 -name 'Android.mk' -printf '%h\n' | grep -v 'test' | uniq -u | sort -u); }
# === Repo mmm Lister ===
function mmml()
{
logfile=/media/adriandc/AndroidDev/Scripts/script_logs.txt;
rm -f $logfile;
mmm -B $@ | tee $logfile;
InstallLog=$(grep -a "target/product/.*/system" $logfile | sort | uniq);
for FilePath in ${InstallLog[*]}; do
if [[ "$FilePath" =~ "/system" && ! "$FilePath" =~ "/NOTICE_FILES" ]]; then
FilePath=$(printf "$FilePath" | tail -1 \
| sed "s/\x1B\[[0-9;]*[JKmsu]//g" \
| sed "s/.*\/\([^\[]*.zip\).*/\1/g");
if [ -f "$FilePath" ]; then
printf " \e[1;36m$FilePath\e[0m";
fi;
fi;
done;
echo "";
echo "";
}
# === ADB Pushes ===
alias adbp='adbro; adbpf';
# === ADB Commit Pusher
function adbpc()
{
tmpfile=$(mktemp);
git show --oneline --name-status | tail -n +2 > $tmpfile;
adbr;
while read line; do
mode=$(echo $line | cut -c 1);
file=$(echo $line | cut -c 3-);
case $mode in
A|M)
adbpf $file;;
D)
if [[ "$file" =~ "proprietary" ]]; then
file=$(printf "$file" | sed "s/.*proprietary\(.*\)/\/system\1/g");
else
file=$(printf "$file" | sed "s/.*\(system.*\)/\/\1/g");
fi;
echo -e " \e[1;36mDeleting $file...\e[0m";
printf " ";
adb shell rm $file;
echo "";;
*);;
esac;
done < $tmpfile;
rm $tmpfile;
}
# === Research shortcuts ===
function highlight() { perl -pe "s/$1/\e[1;0;31m$&\e[0m/ig"; }
function grepb()
{
GREP_COLORS='fn=1;1' grep -air --exclude={*.o,*.a,*.cmd,*.ko} --exclude-dir="\.git" --exclude-dir="\.repo" "$*" .;
}
function grepbs()
{
GREP_COLORS='fn=1;1';
for file in $(find . -type f -not -path "*.git/*" -not -path "*.repo/*" | sort); do
if [ -f "$file" ]; then
found=$(strings $(readlink -f $file) | grep -ai "$*");
if [ ! -z "$found" ]; then
echo -e "\e[1;31m$file :\e[0m $found";
fi;
fi;
done;
}
function grepbn()
{
grep -ailr --color=never --exclude={*.o,*.a,*.cmd,*.ko} --exclude-dir="\.git" --exclude-dir="\.repo" "$*" .;
}
function gck()
{
GREP_COLORS='fn=1;1';
for file in $(find . -name "Kconfig" -o -name "Makefile" -not -path "*.git/*" -not -path "*.repo/*" | sort); do
found=$(strings $(readlink -f $file) | grep -ai "$*");
if [ ! -z "$found" ]; then
echo -e "\e[1;31m$file :\e[0m $found";
fi;
done;
}
function gca()
{
GREP_COLORS='fn=1;1';
for file in $(find . -name "*.mk" -not -path "*.git/*" -not -path "*.repo/*" | sort); do
found=$(strings $(readlink -f $file) | grep -ai "$*");
if [ ! -z "$found" ]; then
echo -e "\e[1;31m$file :\e[0m $found";
fi;
done;
}
alias grepi='grep -i';
alias g='grepb';
alias gs='grepbs';
alias gn='grepbn';
function glc() { GREP_COLORS='fn=1;1' grep --include \*.c --include \*.cpp --include \*.h -anr '.\{80,\}' .; }
function glj() { GREP_COLORS='fn=1;1' grep --include \*.java -anr '.\{100,\}' .; }
function gle() { GREP_COLORS='fn=1;1' grep --include \*.c --include \*.cpp --include \*.h --include \*.java -anr '.* $' .; }
# === ZIP Signer ===
function zipsign()
{
local cwd=$(pwd);
if [ ! -z "$1" ]; then
for file in $@; do
path="$(readlink -f $file)";
cdscripts;
$(getscripts)/android_sign_zip.sh "$path" "inline";
cd $cwd;
done;
else
cdscripts;
$(getscripts)/android_sign_zip.sh "" "inline";
cd $cwd;
fi;
}
# === Updates Helpers ===
function twrpbluekernel()
{
local cwd=$(pwd);
cdtwrp;
repor;
local devicetree=$(totwrp)/device/sony/hayabusa;
cp -v $(tocm13)/out/target/product/hayabusa/kernel $devicetree/prebuilts/kernel;
cd $devicetree;
git reset;
git add -Av;
cd ../../../;
echo "";
local devicetree=$(totwrp)/device/sony/mint;
cp -v $(tocm13)/out/target/product/mint/kernel $devicetree/prebuilts/kernel;
cd $devicetree;
git reset;
git add -Av;
cd ../../../;
echo "";
local devicetree=$(totwrp)/device/sony/tsubasa;
cp -v $(tocm13)/out/target/product/tsubasa/kernel $devicetree/prebuilts/kernel;
cd $devicetree;
git reset;
git add -Av;
cd ../../../;
echo "";
cd $cwd;
}
# === Kernel Helpers ===
function meldtwo()
{
read -e var1;
if [ ! -z "$var1" ]; then var2=$var1; fi;
meld $1/$var2 $2/$var2;
}
# === Terminal Shortcuts ===
function termsp()
{
DevDir=/media/adriandc/AndroidDev;
ROM=$(getine $1 CM-13.0);
gnome-terminal \
--tab --title="Repo" --working-directory="$DevDir/$ROM/" \
--tab --title="Device" --working-directory="$DevDir/$ROM/device/sony/huashan/" \
--tab --title="Kernel" --working-directory="$DevDir/$ROM/kernel/sony/msm8960t/" \
--tab --title="Vendor" --working-directory="$DevDir/$ROM/vendor/sony/" \
--tab --title="Desktop" --working-directory="$(xdg-user-dir DESKTOP)";
}
function rmempty()
{
find . -depth -empty -not -name \*.nomedia -print;
printf " \e[1;31mDelete empty files and folders (y/N) ?\e[0m ";
read key;
if [[ "$key" == "y" || "$key" == "Y" ]]; then
find . -depth -empty -not -name \*.nomedia -delete;
fi;
}
# === Zip AutoPackAndSign ===
function autozipsign()
{
name=$(echo "$1" | sed 's/\///g');
rm $name.zip;
cd $name/;
rm -f META-INF/CERT.RSA;
rm -f META-INF/CERT.SF;
rm -f META-INF/MANIFEST.MF;
rm -rf META-INF/com/android;
zip ../$name.zip * -r;
cd ..;
if [ -z "$2" ]; then
zipsign $name.zip;
fi;
adb sideload $name.zip
}
# === Git helpers ===
function foreachdir()
{
bashfolder="/media/adriandc/AndroidDev/Bash";
source "$bashfolder/bash_android.rc";
source "$bashfolder/bash_huashan.rc";
dircur=$(pwd);
listdir=$(find "$dircur" -maxdepth 1 -type d | sort);
for directory in $listdir
do
if [[ ! "$directory" == "$dircur" ]] && [ -d "$directory" ]; then
cd "$directory";
echo "";
echo " === $(basename $directory) ===";
echo "";
$@
fi;
done;
echo "";
cd "$dircur";
}
# === Log Cleaner ===
function logcl() { cat $1 | sed 's/0x[[:xdigit:]]\{8,8\}/0xaddress/g' | tr -d '\015' > $1.clean; }
# === ADB Tests ===
function adbfb() { adbr; adbs mv $1 $1.temp; }
function adbfr() { adbr; adbs mv $1.temp $1; }
# === Kill and Log Debug ===
function adblk()
{
printf "Process name : ";
if [ ! -z "$1" ]; then
name="$1"; echo "";
else
read name;
fi;
echo -e \\033c; clear;
adbs ps | grep -i $name;
adb logcat -c;
adb shell pkill -f $name;
adbs ps | grep -i $name;
printf "" >adb.log;
adb logcat | tee -a adb.log;
}
# === Shared assets ===
function getine() { if [ ! -z "$1" ]; then echo $1; else echo $2; fi; }
# === Backtracing shortcuts ===
alias adebug='repor; repos; adbr; \
adb shell setprop debug.db.uid 100000; \
adb forward tcp:5039 tcp:5039; \
gdbclient /system/bin/mediaserver :5039 1141';
alias ad2li='addr2line -f -e /media/adriandc/AndroidDev/CM-13.0/out/target/product/huashan/symbols/system/lib/libc.so';
# === WIP shortcuts ===
alias meldh='meld /media/adriandc/AndroidDev/CM-13.0/device/sony/huashan /media/adriandc/AndroidDev/Paths/gerrit-huashan';
alias meldkx='meld /media/adriandc/AndroidDev/CM-13.0/kernel/sony/msm8960t /media/adriandc/AndroidDev/Files/GitHub/msm8x60';
function meldk() { printf " Subpath : "; read a; meld ./$a $1/$a; }
alias permme='UserName="$(whoami)"; sudo chown -cRv $UserName:$UserName ./';
alias touchall='find . -mindepth 1 -exec touch {} \;';
alias dlog='path=$(xdg-user-dir DESKTOP); xargs log.$(date).log';
function dupl() { cat $1 | sort | uniq -cd; }
alias lsmk='ls -1 | sed "s/\(.*\)/ utils\/\1 \\\/"';
function gitkdev()
{
chromium-browser https://github.com/CyanogenMod/android_kernel_sony_msm/blob/cm-13.0/$1;
chromium-browser https://github.com/CyanogenMod/android_kernel_google_msm/blob/cm-13.0/$1;
chromium-browser https://github.com/CyanogenMod/android_kernel_sony_msm8960t/blob/cm-12.1/$1;
}
function meldt() { meld $1 ../msm8960t/$1; }
function adbkillsetup() { adb root; adb wait-for-device; while [ 1 ]; do adb shell kill $(adb shell ps | grep setup | awk '{ print $2 }'); done; }
function adbtinymix() { adb shell /system/bin/tinymix; }
# === Apps shortcuts ===
function adbu() { echo ""; echo " [ Launching '$1' ]"; echo ""; \
echo " Optimizing..."; adb $2 shell pm force-dex-opt $1; \
echo " Killing..."; adb $2 shell pkill $1; echo ""; }
function ntf() { notify-send "$*"; }
# === Git vars ===
gituserdefault='AdrianDC';
gitremotedefault='AdrianDC';
gitreviewdefault='github';
gitrebasedefault=25;
# === Git commits ===
alias gitc='git commit -S';
alias gitcs='git commit -S -s';
alias gitca='git commit -S --amend';
alias gitcae='git commit -S --amend --no-edit';
alias gitcauthor='git commit -S --amend --no-edit --author="$(git config --global --get user.name) <$(git config --global --get user.email)>"';
alias gitcid='scp -p -P 29418 $gituserdefault@review.cyanogenmod.org:hooks/commit-msg .git/hooks/; chmod u+x ./.git/hooks/commit-msg; git commit --amend --no-edit; git commit --amend';
alias gitcidh='scp -p http://review.cyanogenmod.org:hooks/commit-msg .git/hooks/; chmod u+x ./.git/hooks/commit-msg; git commit --amend --no-edit; git commit --amend';
alias gitrev='git revert -S';
# === Git commit with infos ===
function gitcci()
{
clear; url=$1;
if [[ $url =~ 'github' && ! $url =~ '.patch' ]]; then url='$url.patch'; fi;
file=$(mktemp);
curl -s $url 2>nul >"$file";
local line_subject=$(($(sed -n "1,/Subject:/=" "$file" | tail -1)+1));
local line_messageend=$(($(sed -n "1,/---/=" "$file" | tail -1)-1));
local subject=$(grep "Subject: " "$file" | tail -1 | cut -c10-);
cat $file;
git add -Ap;
git commit \
-m "$subject"$'\n'"$(sed -n "${line_subject},${line_messageend}p" "$file")" \
--date="$(grep "Date:" "$file" | tail -1) \
--author="$(grep "Author:" "$file" | tail -1);
rm "$file";
}
# === Repo Branch ===
function repogetbranch()
{
local branch='';
local infos=$(repo info . 2>&1);
if [[ ! "$infos" =~ 'repo to be installed' ]] && [[ ! "$infos" =~ 'sudo apt' ]]; then
branch=$(echo "$infos" \
| grep -i 'Manifest branch' \
| head -n 1 \
| sed 's/.*\/heads\/\(.*\)/\1/');
fi;
if [ -z "$branch" ] || [[ "$branch" =~ "Manifest" ]]; then
branch="cm-13.0";
fi;
echo "$branch";
}
# === Git pushing ===
function gitpu()
{
remote=$(getine $1 gitremotedefault);
if [ ! -z "$2" ]; then
branch=$2;
else
branch=$(repogetbranch);
fi;
echo "";
command="git push -f $remote HEAD:refs/heads/$branch";
printf " $command [Enter] ? "; read key;
echo "";
git fetch $remote $branch;
$command;
echo "";
}
alias gitpa='gitpu $gitremotedefault';
alias gitpa14='gitpu $gitremotedefault cm-14.0';
alias gitpa6='gitpu $gitremotedefault aosp-6.0';
alias gitpaa6='gitpu $gitremotedefault android-6.0';
alias gitpam='gitpu $gitremotedefault multirom';
alias gitpamm='gitpu $gitremotedefault marshmallow';
alias gitpan='gitpu $gitremotedefault nougat';
alias gitpat='gitpu $gitremotedefault twrp';
alias gitpp='gitpu project master';
function gitpacaf() { branch=$(getine $1 "LA.AF.1.2.1");
git push -f -u https://github.com/AdrianDC/android_kernel_sony_msm8x60.git HEAD:refs/heads/$branch; }
alias gitpb='gitpu backup';
alias gitpaicp='gitpu aicp mm6.0';
alias gitpold='gitpu old';
function gitpo() { command="git push origin $(getine $1 $(repogetbranch))"; \
echo ""; printf " \e[1;31mTarget: \e[0m";
git remote -v | grep origin | head -1 | cut -f2 | cut -d' ' -f1;
echo -e " \e[1;37mCommand: $command\e[0m"; printf " > Proceed with origin push (y/N) ? "; read key; \
if [[ "$key" == "y" || "$key" == "Y" ]]; then echo ""; $command; fi; echo ""; }
alias gitpf='git push -f';
function gitck() { branch=$(getine $1 $(repogetbranch)); git fetch github $branch >/dev/null; git diff HEAD github/$branch; }
function gitcn() { branch=$(getine $1 $(repogetbranch)); git fetch github $branch; git diff HEAD github/$branch; }
# === Git push helpers ===
function gitpamrom()
{
git cherry-pick 3526e39dae113144667350f7babbd80d494a5756;
git cherry-pick 4590f1ad4f1bdadce3f5d1d2af6c4c2c6a0867f8;
git cherry-pick 271719c6d4353ba210c69f1cdaf03464b56988c5;
git cherry-pick 9587bac59e9a17bd3631cab64173ca99edeeb549;
gitpa multirom;
git reset --hard HEAD~4;
}
# === Git resetting ===
alias gitrh='git reset FETCH_HEAD --hard';
alias githd='git reset HEAD --hard';
alias gitcl='git reset HEAD --hard; git stash -u';
alias gitro='git reset HEAD^ --hard';
alias gitsl='git reset HEAD^; gitap; gitcae';
alias gitrl='git revert HEAD -n; git commit -m "Revert"; git reset HEAD^; git add -p';
alias gitri='git reset HEAD^';
alias gitrt='git reset --hard';
# === Git rebasing ===
function gitr() { git rebase HEAD~$(getine $1 $gitrebasedefault) -i; }
function gitredit() { GIT_SEQUENCE_EDITOR="sed -i -e 's/pick/edit/g'" git rebase HEAD~$(getine $1 $gitrebasedefault) -i; }
function gitrf() { git rebase $1^ -i; }
alias gitra='git rebase --abort';
alias gitrc='git rebase --continue';
alias gitre='git rebase --edit-todo';
alias gitrs='git rebase --skip';
function gitrb() { branch=$(getine $1 $(repogetbranch)); git fetch github $branch; git rebase github/$branch; }
function gitrbo() { branch=$(getine $1 $(repogetbranch)); git fetch origin $branch; git rebase origin/$branch; }
function gitrbs() { branch=$(getine $1 $(repogetbranch)); git fetch source $branch; git rebase source/$branch; }
function gitrbm() { branch=$(getine $1 LA.AF.1.2.1_rb1.6); git fetch mifl $branch; git rebase mifl/$branch; }
function gitrbad() { branch=$(getine $1 $(repogetbranch)); git fetch AdrianDC $branch; git rebase AdrianDC/$branch; }
function gitrbma() { branch=$(getine $1 cm-13.0); git fetch ADC $branch; git rebase ADC/$branch; }
# === Git branch ===
function gitbc() { branch=$(getine $1 $(repogetbranch)); review=$(getine $2 $gitreviewdefault);
git fetch $review $branch; git branch $branch --track $review/$branch; git checkout $branch; }
function gitbt() { branch=$(getine $1 $(repogetbranch)); git branch $branch; git checkout $branch; }
alias gitbd='git branch -D';
alias gitbv='git fetch $gitreviewdefault $(git rev-parse --abbrev-ref HEAD); git branch -vv';
function gitbvv() { branch=$(getine $1 $(repogetbranch));
git fetch origin $branch;
git branch tempbck;
git branch -D $branch;
git branch $branch --track origin/$branch;
git checkout $branch;
git reset --hard tempbck;
git branch -D tempbck;
echo ""; gitbv; }
alias gitrv='git remote -v';
function gitremoteset()
{
git remote add $1 $2 2> /dev/null;
git remote set-url $1 $2;
git remote -v | grep $1;
}
function gitremoteadaptset()
{
local repository='CyanogenMod';
local remote='origin';
if [ ! -z "$1" ]; then remote="$1"; fi;
if [ ! -z "$2" ]; then repository="$2"; fi;
local target=$(git remote -v \
| grep -i github \
| head -n 1 \
| awk '{ print $2 }');
if [ -z "$target" ]; then
local project=$(git remote -v \
| grep -v -i github \
| head -n 1 \
| awk '{ print $2 }' \
| sed 's/.*\.com\///' \
| sed 's/platform/android/' \
| sed 's/\//_/g');
echo $project;
target='http://github.com/'$repository'/'$project;
fi;
echo $target;
target=$(echo $target \
| sed "s/\(http:\/\/\|https:\/\/\|git:\/\/\)\(.*\)\/[^\/]*\/\(.*\)/http:\/\/\2\/$repository\/\3/");
if [ ! -z "$3" ]; then
target=$(echo "$target" | sed "s/$3//");
fi;
gitremoteset $remote $target;
}
function gitraa() { gitremoteadaptset 'AdrianDC' 'AdrianDC' ''; }
function gitrao() { gitremoteadaptset 'origin' 'CyanogenMod' ''; }
function gitraoo() { gitremoteadaptset 'origin' "$1" ''; }
function gitraot() { gitremoteadaptset 'origin' 'TheMuppets' ''; }
function gitrat() { gitremoteadaptset 'twrp' 'TeamWin' ''; }
function gitrai() { gitremoteadaptset 'aicp' 'AICP' 'android_'; }
function gitrab() { gitremoteset backup https://github.com/AdrianDC/android_development_backup.git; }
alias gitch='git checkout';
alias gitbaclean='git fetch $gitremotedefault; git branch -r | grep $gitremotedefault | sed "s/$gitremotedefault\/\(.*\)/\1/g" | xargs -L 1 git push $gitremotedefault --delete';
# === Git adds ===
alias gitaa='git add . -Av';
alias gitap='git add -p';
alias gitaap='git add . -Ap';
alias gitacf='gitap; gitcae; gitpf';
# === Git cherry-picks ===
alias gitcp='git cherry-pick';
alias g='git cherry-pick';
alias gitcpc='git reset; git cherry-pick --continue';
alias g='git cherry-pick';
function gitcpf() { git fetch $1; git cherry-pick FETCH_HEAD; }
function gitcpl() { while [ 1 ]; do echo ""; printf " Commit : "; read commit; gitcp $commit; done; echo ""; }
function gitcpa() { a="$1"; b="$2"; if [ -z "$b" ] && [ -z "${a##*[!0-9]*}" ]; then b="$a"; a=""; fi;
git fetch $gitremotedefault $(getine $b $(repogetbranch)); git cherry-pick FETCH_HEAD~$(getine $a 0); }
function gitcpal()
{
if [ -z "$2" ]; then
echo "usage: gitcpal branch commitcount";
return;
fi;
git cherry-pick --abort;
git fetch $gitremotedefault $(getine $1 $(repogetbranch));
git cherry-pick $2^..FETCH_HEAD;
}
function gitfcp() { git fetch $1 $2; git cherry-pick FETCH_HEAD; }
function gitcpr()
{
git show $1 --no-color | sed "s/$2/$3/g" | patch;
}
function gitcpd()
{
if [ -z "$3" ]; then
echo " Usage: gitcpd from_folder to_folder commit_sha1";
return;
fi;
git cherry-pick $3;
for file in $(git diff-tree --no-commit-id --name-only -r $3); do
file_target=$(echo $file | sed "s/$1/$2/");
cp -v $file $file_target;
git add -v $file_target;
done;
}
alias gitclone="git clone --single-branch -b cm-13.0";
function gitclonedevice()
{
if [ -z "$1" ]; then
echo " Usage: gitclonedevice brand_codename";
else
gitclone https://github.com/CyanogenMod/android_device_$1;
fi;
}
function gitcpaicp()
{
git fetch aicp mm6.0;
git reset --hard aicp/mm6.0;
git fetch origin cm-13.0;
echo "";
echo -e " \e[1;34m\e[4;34mBranch : origin/cm-13.0\e[0m";
git log --pretty=oneline -n 6 origin/cm-13.0;
echo "";
echo -e " \e[1;34m\e[4;34mBranch : aicp/mm6.0\e[0m";
git log --pretty=oneline -n 6 aicp/mm6.0;
echo "";
printf " \e[1;34m\e[4;34mNumber of commits :\e[0m ";
read cnt;
git cherry-pick FETCH_HEAD~$cnt..FETCH_HEAD;
echo "";
printf " \e[1;34m\e[4;34mPress Enter to diff with origin/cm-13.0 :\e[0m ";
read key;
git diff HEAD origin/cm-13.0;
echo "";
headsha1=$(git log --max-count=1 --format=format:%H -- .);
for i in `seq $(($cnt-1)) -1 0`; do
echo -e " \e[1;34m\e[4;34m===[ $headsha1~$i ]===\e[0m";
echo "";
git reset --hard $headsha1~$i;
git show HEAD;
gitstat aicp mm6.0;
gitpushreview http://gerrit.aicp-rom.com AICP for mm6.0;
gitpushreview http://gerrit.aicp-rom.com AICP heads mm6.0;
echo "";
done;
}
# === GitHub Url Cherry-Pick ===
function gitcpu()
{
if [ -z "$1" ]; then
echo " Usage: gitcpu githuburltocommit [branch]";
return;
fi;
link="$1";
project="$(echo "$link" \
| sed 's/.*\(github.com\/.*\)\/commit\/.*/http:\/\/\1/')";
commit="$(echo "$link" \
| sed 's/.*\/commit\/\(.*\)/\1/')";
if [ ! -z "$2" ]; then
branch="$2";
else
branch="cm-13.0";
fi;
if [ -z "$project" ] || [ -z "$commit" ]; then
echo " Error: Not a GitHub commit url '$link'";
return;
fi;
git fetch $project $branch;
echo "";
git show $commit --oneline --stat;
echo "";
git cherry-pick $commit;
}
# === GitHub Url Cherry-Pick ===
function gitcpup()
{
if [ ! -z "$2" ] && [ ! -z "$3" ]; then
echo "$2";
curl $1.patch \
| sed "s/$2/$3/" \
| git apply -v --index;
else
curl $1.patch \
| git apply -v --index;
fi;
}
# === GitHub Url Fetch-Reset ===
function gitfcu()
{
if [ -z "$1" ]; then
echo " Usage: gitfpu githuburltoproject [branch]";
return;
fi;
link="$1";
if [ ! -z "$2" ]; then
branch="$2";
else
branch="cm-13.0";
fi;
if [ -z "$link" ]; then
echo " Error: Not a GitHub url '$link'";
return;
fi;
git fetch $link $branch;
echo "";
git reset --hard FETCH_HEAD;
}
# === Git stash ===
alias gits='git stash';
alias gitsp='git stash -p';
alias gitsu='git stash -u';
alias gitspop='git stash pop';
# === Git tools ===
alias gitd='git diff';
function gitdi()
{
git diff --name-status;
git ls-files --others --exclude-standard | awk '{print "U " $0}';
}
alias gitlo='git log --pretty=oneline';
alias gitloo='git log --pretty=format:"%C(yellow)%h %Cred%ad %Creset%s" --date=short --all --';
alias gitshow='git show --name-status;';
alias gitshf='git show --pretty=full;';
alias gitlc='git show --name-only --oneline';
alias gitdfs='git diff-tree --no-commit-id --name-status -r';
function gitdf()
{
if [ -z "$2" ]; then
echo " Usage: gitdf sha1commit filepath";
return;
fi;
git diff $1^:$2 $1:$2;
}
function gitstat()
{
if [ -z "$2" ]; then
echo " Usage: gitstat remote branch";
return;
fi;
echo "git fetch $1 $2; git rev-list --left-right --count HEAD...FETCH_HEAD;";
git fetch $1 $2;
git diff HEAD...FETCH_HEAD;
echo "";
printf " New changes - missing : ";
git rev-list --left-right --count HEAD...FETCH_HEAD;
}
alias gitst='gitstat origin cm-13.0';
alias gitst13='gitstat origin cm-13.0';
alias gitst14='gitstat origin cm-14.0';
alias gitsts14='gitstat origin staging/cm-14.0';
alias gitsto='gitstat origin $(git rev-parse --abbrev-ref HEAD)';
alias gitsta='gitstat AdrianDC cm-13.0';
alias gitsta6='gitstat AdrianDC aosp-6.0';
alias gitstaa6='gitstat AdrianDC android-6.0';
alias gitstatw='gitstat AdrianDC twrp';
alias gitsti='gitstat aicp mm6.0';
alias gitstt='gitstat twrp android-6.0';
function gitsf() { echo ""; for i in `seq 1 $(getine $1 1)`; do
gitlc HEAD~$(($i-1)); echo ""; done; }
function gitsfd() { echo ""; for i in $(git log --format=format:%H -- $(getine $1)); do
gitlc $i; echo ""; printf " > Press Enter... "; read key; done; }
alias gitmt='git mergetool';
function gitme()
{
path=$(timeout 1 git mergetool 2>/dev/null \
| head -n 2 \
| tail -1);
if [ -f "$path" ]; then
gedit "$path";
printf "Done ? [Enter] ";
read;
git add "$path";
else
echo " '$path' not found...";
fi;
}
function gitmte()
{
git diff --name-only | uniq;
echo "";
for file in $(git diff --name-only | uniq); do
printf " - $file : ";
gedit $file;
printf "Done ? [Enter / Ctrl+C] ";
read;
git add $file;
done;
}
alias githi='git update-index --assume-unchanged';
alias gitsh='git update-index --no-assume-unchanged';
alias gitlod='git log --pretty=oneline --';
function gitloc() { path=$(xdg-user-dir DESKTOP);
git log --pretty=oneline --no-merges HEAD -- . | tee $path/gitloc$1.full.log;
cat $path/gitloc$1.full.log | cut -c 42-| sort | tee $path/gitloc$1.comp.log; }
function gitlos()
{
if [ ! -z "$2" ]; then cnt=$2; else cnt=30; fi;
echo -e " \e[1;37mSearching for $1 in last $cnt commits...\e[0m";
echo "";
for sha1 in $(git log --max-count=$cnt --format=format:%H -- .); do
if [ ! -z "$(git show $sha1 | grep -i "$1")" ]; then
git show --name-only --oneline $sha1; echo "";
fi;
done;
}
function gite() { gedit $1; printf "Done ? [Enter] "; read; git add $1; }
alias gitrerere='git config --global rerere.enabled';
alias gpglist='gpg --list-secret-keys --keyid-format LONG';
alias gpgsilent='echo "no-tty" >> ~/.gnupg/gpg.conf';
alias gpgenable='git config --global commit.gpgsign true';
alias gpgdisable='git config --global commit.gpgsign false';
alias gpgsigning='git config --global user.signingkey';
alias gitshowsg='git config --global alias.logs "log --show-signature"';
alias gitpwstore='git config --global credential.helper store';
alias gitfix='rm -fv .git/COMMIT_EDITMSG*; rm -fv .git/.COMMIT_EDITMSG.swp';
# === Git mergers ===
function gitmerges()
{
if [ ! -z "$2" ]; then cnt=$2; else cnt=30; fi;
echo "";
echo -e " \e[1;37mSearching mergeable commits in $1 tree...\e[0m";
echo "";
git rev-list $1 --reverse --pretty=oneline -- . \
| tail -n $cnt \
| while read line;
do
sha1=$(echo $line | cut -c -40);
title=$(echo $line | cut -c 42-);
if [ -z "$(git rev-list HEAD --pretty=oneline -- . \
| grep -i "$title")" ]; then
echo -e " \e[1;31m$sha1 : \e[1;37m$title\e[0m";
git cherry-pick $sha1;
git reset --hard HEAD;
echo "";
fi;
done;
}
# === Git repos / folders comparator ===
function gitlodc()
{
dirlog=$(getine $3 ".");
if [ -z "$2" ]; then
echo " Usage: gitlodc repo_one_path repo_two_path sub_folder [sort]";
return;
fi;
dircur=$(pwd);
tmpdir=$(mktemp -d);
cd "$1";
gitlod "$dirlog" | cut -d' ' -f2- > "$tmpdir/gitdir1.log";
if [ -z "$4" ]; then
sort "$tmpdir/gitdir1.log" -o "$tmpdir/gitdir1.log";
fi;
cd "$2";
gitlod "$dirlog" | cut -d' ' -f2- > "$tmpdir/gitdir2.log";
if [ -z "$4" ]; then
sort "$tmpdir/gitdir2.log" -o "$tmpdir/gitdir2.log";
fi;
meld "$tmpdir/gitdir1.log" "$tmpdir/gitdir2.log";
rm -rf "$tmpdir";
cd "$dircur";
}
# === Git kernels meld ===
function gitkmeld()
{
subdir=$(getine $2 "");
if [ -z "$1" ]; then
echo " Usage: gitkmeld second_kernel_path sub_folder";
return;
fi;
meld ./$subdir/ $1/$subdir/;
}
# === Git killers ===
function gitonebranch()
{
git fetch AdrianDC;
git fetch AdrianDC refs/heads/*:refs/heads/*;
git fetch AdrianDC refs/tags/*:refs/tags/*;
git branch -r | sed 's/AdrianDC\/\(.*\)/\1/' \
| grep -v "HEAD" \
| grep -v $(git rev-parse --abbrev-ref HEAD) \
| xargs -I {} sh -c 'printf " Removing branch {} : "; git push AdrianDC :{};';
git tag -l | xargs -I {} sh -c 'printf " Removing tag {} : "; git push AdrianDC :{}; printf " "; git tag -d {};';
}
# === Compilations ===
alias kernelcfg='make ARCH=arm CROSS_COMPILE=arm-linux-androideabi- cm_viskan_huashan_defconfig; \
cp -fv ./.config ./arch/arm/configs/cm_viskan_huashan_defconfig; rm -f ./.config';
alias kernelcln='rm ';
# === Linux Commands ===
function gohibernate() { \
sudo swapon -a; \
sudo swapon -s; \
sudo pm-hibernate; \
}
# === Linux Functions ===
function mtpmountdisable()
{
gsettings set org.cinnamon.desktop.media-handling automount-open false;
gsettings set org.cinnamon.desktop.media-handling automount false;
}
# === Debug builds ===
function kernelmassbuilder()
{
CurHead=3bb6504b937f9cd4828a78c45c0194752f67d37e;
Counter=760;
while [ $Counter -ge 0 ]; do
echo $Counter
git reset --hard $CurHead~$Counter;
kerzip $Counter;
Counter=$((Counter - 10));
done;
}
# === BACKUP : Git patchs ===
function gitacp()
{
clear; url=$1; echo $url;
#url="http://kernel.opensuse.org/cgit/kernel/patch/?id=620e5050827008ab207a8dfcc44cb79f07f1942c";
if [[ ! $url =~ '.patch' ]]; then url='$url.patch'; fi;
curl -s $url 2>nul > /tmp/bash_android_tmp.patch;
git apply --stat "/tmp/bash_android_tmp.patch";
git am --abort;
git am -3 "/tmp/bash_android_tmp.patch";
}
# === BACKUP : gerrit-cherry-pick ===
alias gerrit-cherry-pick='if ! hash gerrit-cherry-pick 2>/dev/null; then \
curl -Lo ~/bin/gerrit-cherry-pick http://review.cyanogenmod.org/tools/bin/gerrit-cherry-pick; \
chmod +x ~/bin/gerrit-cherry-pick; \
fi; \
gerrit-cherry-pick';
# find . -type f | cut -c 2- | xargs adb shell ls -l