-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
aa.py
453 lines (406 loc) · 10.8 KB
/
aa.py
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
#!/usr/bin/env python3
import os
import shutil
import platform
import subprocess
from time import sleep
cyan='\033[96m'
end='\033[0m'
back='\033[44m'
def yesno(txt):
txt=txt.lower()
if (txt=="y" or txt=="yes" or txt=="yep" or txt=="yeah"):
return True
if (txt=="n" or txt=="no" or txt=="nope" or txt=="not"):
return False
return None
def angryinput(text="",list=None,func=None):
while (1):
tt=input(text)
if func!=None:
if func(tt)==None:
continue
if list!=None:
if not (tt in list):
continue
return tt
def ResetBash():
print("\n So Run: source ~/.bashrc \n")
sleep(4)
AsciiArt=r'''
___ ___
/ \ / \
/ ^ \ / ^ \
/ /_\ \ / /_\ \
/ _____ \ / _____ \
/__/ \__\ /__/ \__\
_______. _______ .___________. __ __ .______
/ || ____|| || | | | | _ \
| (----`| |__ `---| |----`| | | | | |_) |
\ \ | __| | | | | | | | ___/
.----) | | |____ | | | `--' | | |
|_______/ |_______| |__| \______/ |__|
'''
Script=r'''
#####AA Zone#####
#11
###codes,color and etc###
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
###alias###
alias lsx="ls -ltrhAi --author --color=auto --hyperlink=always -s"
alias KILLME="sudo rm -rf /"
alias LAGME=":(){ :|: & };:"
alias myip="curl ifconfig.co"
###funcs###
mkcdir ()
{
mkdir -p -- "$1" &&
cd -P -- "$1"
}
rmx ()
{
RED="\e[1;31m"
YELLOW="\e[1;33m"
NOCOLOR="\e[0m"
Forced="1"
FolderCon="1"
for var in "$@"
do
if [ "$var" = "-f" ] || [ "$var" = "--force" ]
then
Forced="0"
fi
done
echo -e "${YELLOW}"
pwd
echo -e "${NOCOLOR}"
echo -e "${RED}"
lsx -lAd "${@}" | head -n 10
ret=$?
varnumline=$(($(ls -lAd "${@}" | wc -l)-10))
if (( varnumline > 0 ))
then
echo -e "and $varnumline more"
fi
echo -e "${NOCOLOR}"
if [ "$ret" -eq "0" ]
then
if [ "$Forced" -eq "0" ]
then
answertodel="y"
echo
else
printf "Are you Sure (Type y for continue): "
read answertodel
fi
else
answertodel="Danger"
fi
if [ "$answertodel" = "y" ] || [ "$answertodel" = "Y" ]
then
echo "${@:-$(ls -A)}" | xargs -l rm -rf
else
echo -e "${RED}Operation cancelled${NOCOLOR}"
return 1
fi
return 0
}
rmhere ()
{
RED="\e[1;31m"
YELLOW="\e[1;33m"
NOCOLOR="\e[0m"
DELHEREPATH=$PWD
echo -e "${YELLOW}"
echo "Files which gonna be deleted:"
echo -e "${NOCOLOR}"
echo -e "${RED}"
lsx
echo -e "${NOCOLOR}"
rmx
if [ "$?" -eq "0" ]
then
cd ..
rmdir $DELHEREPATH
fi
}
fexe (){
chmod +x "$1"
./"$1"
}
giton(){
git init .
touch README.md
touch LICENSE
touch .gitignore
git add *
git add .gitignore
git commit -m "${1:-"Initial Commit"}"
}
#-p for push
gitup(){
git add .
if [[ "$1" = "" ]]
then
git commit
else
git commit -m $1
fi
}
gitconfg(){
git config --global user.name "$1"
git config --global user.email "$2"
}
gitconf(){
git config user.name "$1"
git config user.email "$2"
}
boilcpp(){
z=$1
if [[ "$z" = "" ]]
then
z="main"
fi
if [[ -d "$z" ]]
then
echo "a dir with this name exist! try another name or delete it by \"rm -rf $z\" "
return -1
fi
mkdir "$z"
cd "$z"
############################################### DEFAULT CODE
echo "#include <iostream>" >> main.cpp
echo "" >> main.cpp
echo "// using namespace std;" >> main.cpp
echo "" >> main.cpp
echo "int main(int argc, char *argv[]){" >> main.cpp
echo " std::cout << \"AA is OOF\\n\";" >> main.cpp
echo " return 0;" >> main.cpp
echo "}" >> main.cpp
###############################################
}
boilc(){
z=$1
if [[ "$z" = "" ]]
then
z="main"
fi
if [[ -d "$z" ]]
then
echo "a dir with this name exist! try another name or delete it by \"rm -rf $z\" "
return -1
fi
mkdir "$z"
cd "$z"
############################################### DEFAULT CODE
echo "#include <stdio.h>" >> main.c
echo "" >> main.c
echo "int main(int argc, char *argv[]){" >> main.c
echo " printf(\"AA is OOF\\n\");" >> main.c
echo " return 0;" >> main.c
echo "}" >> main.c
###############################################
}
runc(){
z=$1
if [[ "${z##*.}" = "c" ]]
then
z="${z%.*}"
fi
if [[ "$z" = "" ]]
then
z="main"
fi
rm "$z.o" "$z" > /dev/null 2>&1
gcc -std=c2x "$z.c" -o "$z.o" #C flags / Bleeding edge features
link "$z.o" "$z"
chmod +x "$z"
echo ; echo
echo "##################### Program Start #####################"
echo
./"$z"
}
runcpp(){
z=$1
if [[ "${z##*.}" = "cpp" ]]
then
z="${z%.*}"
fi
if [[ "$z" = "" ]]
then
z="main"
fi
rm "$z.o" "$z" > /dev/null 2>&1
g++ -Wno-error -std=c++2a -fconcepts "$z.cpp" -o "$z.o" #C++ flags / Bleeding edge features / take a look at https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
link "$z.o" "$z"
chmod +x "$z"
echo ; echo
echo "##################### Program Start #####################"
echo
./"$z"
}
#FUTURE : Online Update
#####AA Zone#####
'''
print(back+cyan+AsciiArt)
print("A Tiny Script By AARMN The Limitless To Ease Bash With Some Funcs And Aliases\n")
if (platform.system()!="Linux"):
print("Installer Work Only On Gnu\Linux OS , If You Have Bash Installed In Your OS, Copy Script Var From Source to Your .bashrc File In Home Folder Of Your OS")
exit()
bash=str(subprocess.check_output(["bash","--version"])).find("GNU bash")
if (bash==-1):
print("There Is No Bash In Your System PATH , Try to Install Or Reinstall It")
exit()
Home=os.path.expanduser("~")
try:
Bashrc=open(os.path.join(Home,".bashrc"),"r")
except IOError:
ans3=yesno(angryinput("You Don't Have A Bashrc, Can I Create One? (Yes/No)",func=yesno))
if not (ans3):
exit()
Bashrc=open(os.path.join(Home,".bashrc"),"w+")
Bashrc.close()
Bashrc=open(os.path.join(Home,".bashrc"),"r")
ans=None
BashrcString=Bashrc.read()
Bashrc.close()
StartScript=BashrcString.find('#####AA Zone#####\n')
EndScript=BashrcString.find('#####AA Zone#####\n',StartScript+1)
WithoutScript=BashrcString[0:StartScript]+BashrcString[EndScript+17:-1]
InstalledScript=BashrcString[StartScript:EndScript+17]
TagCount=0
def InstallScript():
try:
Bashrc=open(os.path.join(Home,".bashrc"),"a")
except IOError:
print("I Think Bashrc Is Write Protect, Fix It And Run Code Again")
exit()
Bashrc.write(Script)
Bashrc.close()
def UninstallScript():
try:
Bashrc=open(os.path.join(Home,".bashrc"),"w")
except IOError:
print("I Think Bashrc Is Write Protect, Fix It And Run Code Again")
exit()
Bashrc.write(WithoutScript)
Bashrc.close()
def FindVer(start,scriptstr):
endline="\n"
ListTmpVer=list()
step=start+19
while(scriptstr[step]!=endline):
ListTmpVer.append(scriptstr[step])
step+=1
return int(''.join(ListTmpVer))
Bashrc=open(os.path.join(Home,".bashrc"),"r")
for line in Bashrc:
if (line=="#####AA Zone#####\n"):
TagCount+=1
Bashrc.close()
nonew="This Script Don't Have A New Version Of AA"
installthem="To Upgrade Bash to Next Level We Suggest You to Install More Fancy Stuff too \nDo You Want to Install:"
bashit="1.Bashit"
omb="2.Oh My Bash"
iowt="3.None Of Them, AA is Enough"
donesad="Done :("
donehappy="Done :)"
wisechoice="Wise Choice :)"
letsinstall="AA Is Not Installed Yet, Do You Want to Install? (Yes/No) : "
pbbutinstalled="AA Is Not Installed Successfully (Or You Want to Trick Us ... HAHAHAHA), Do You Want to Install Anyway? (Just Add Commands to End) (Yes/No) : "
cancelit3="3.Cancel"
cancelit2="2.Cancel"
uninstallit="1.Uninstall AA"
newincompatver="Your Version Is Newer And Backward Incompatible Or You Have A Corrupt Version of AA In Your Bashrc,In This Situation Try Delete It Manually And Have A New Installed"
upgradeit="2.Down/Up-grade AA"
otherver="If You Want to Upgrade Or Find It Useless, This Script Contain a diffrent ver"
olderver="But It's Older :("
newerver="Good News, It's New :)"
resetshell="To Effect Changes You Need To Run A New Bash Or Source Bashrc, Do You Want To Source Bashrc? (If You Are Already Running This In Bash Its Recommended) (Yes/No) : "
if (TagCount==0):
ans=yesno(angryinput(letsinstall,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donehappy)
elif (TagCount==1):
ans=yesno(angryinput(pbbutinstalled,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donehappy)
elif (TagCount==2):
if (('\n'+InstalledScript+'\n')==Script):
print(nonew)
print(uninstallit)
print(cancelit2)
ans2=0
ans2=int(angryinput(list=["1","2"]))
if (ans2==1):
UninstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donesad)
else:
print(wisechoice)
else:
print(otherver)
try:
if (FindVer(0,InstalledScript)<FindVer(1,Script)):
print(newerver)
else :
print(olderver)
except:
print(newincompatver)
print("We Have 3 Options: ")
print(uninstallit)
print(upgradeit)
print(cancelit3)
ans2=0
ans2=int(angryinput(list=["1","2","3"]))
if (ans2==1):
UninstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donesad)
if (ans2==2):
UninstallScript()
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donehappy)
else:
ans=yesno(angryinput(pbbutinstalled,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
print(donehappy)
print(end + "\033[2J" + "\033[1;1H")
cols=shutil.get_terminal_size((80, 20)).columns
print()
print("This project is more about ease and fun, if you like this give us star on gitlab and github, check my other projects, report bugs, pull request new features and so on".center(cols))
print("Wish you bests! Have a good day :)".center(cols))
print()
print()
print()