Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvement #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 77 additions & 43 deletions aa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ def angryinput(text="",list=None,func=None):
continue
return tt


def ResetBash():
print("\n So Run: source ~/.bashrc \n")
sleep(4)

def DetectShell():
Shell = os.popen('echo $SHELL').read()
if('zsh' in Shell):
return '.zshrc'
return '.bashrc'

def ResetShell():
if(DetectShell() == '.bashrc'):
print("\n So Run: source ~/.bashrc \n")
sleep(4)
elif(DetectShell() == '.zshrc'):
print("\n So Run: source ~/.zshrc \n")
sleep(4)
AsciiArt=r'''
___ ___
/ \ / \
Expand Down Expand Up @@ -288,35 +296,40 @@ def ResetBash():
#####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()

if(DetectShell() == '.bashrc'):
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()
else:
zsh=str(subprocess.check_output(["zsh","--version"])).find("zsh")
if (zsh==-1):
print("your default shell is zsh but There Is No zsh In Your System PATH , Try to Install Or Reinstall It")
exit()
Home=os.path.expanduser("~")

try:
Bashrc=open(os.path.join(Home,".bashrc"),"r")
Shell=open(os.path.join(Home,DetectShell()),"r")
except IOError:
ans3=yesno(angryinput("You Don't Have A Bashrc, Can I Create One? (Yes/No)",func=yesno))
if(DetectShell() == '.bashrc'):
ans3=yesno(angryinput("You Don't Have A .bashrc, Can I Create One? (Yes/No)",func=yesno))
elif(DetectShell() == '.zshrc'):
ans3=yesno(angryinput("You Don't Have A .zshrc, Can I Create One? (Yes/No)",func=yesno))
if not (ans3):
exit()
Bashrc=open(os.path.join(Home,".bashrc"),"w+")
Bashrc.close()
Shell=open(os.path.join(Home,DetectShell()),"w+")
Shell.close()

Bashrc=open(os.path.join(Home,".bashrc"),"r")
Shell=open(os.path.join(Home,DetectShell()),"r")
ans=None
BashrcString=Bashrc.read()
Bashrc.close()
BashrcString=Shell.read()
Shell.close()
StartScript=BashrcString.find('#####AA Zone#####\n')
EndScript=BashrcString.find('#####AA Zone#####\n',StartScript+1)
WithoutScript=BashrcString[0:StartScript]+BashrcString[EndScript+17:-1]
Expand All @@ -325,20 +338,39 @@ def ResetBash():

def InstallScript():
try:
Bashrc=open(os.path.join(Home,".bashrc"),"a")
Shell=open(os.path.join(Home,DetectShell()),"a")
except IOError:
print("I Think Bashrc Is Write Protect, Fix It And Run Code Again")
print("I Think Shell Is Write Protect, Fix It And Run Code Again")
exit()
Bashrc.write(Script)
Bashrc.close()
Shell.write(Script)
Shell.close()

def InstallExtra():
print(letsinstall)
if(DetectShell() == '.bashrc'):
print(omb)
print(iowt)
OptionList = ['0','1']
elif(DetectShell() == '.zshrc'):
print(omz)
print(iowt)
OptionList = ['0','1']
ExtraTools = int(angryinput(list=OptionList))
if(DetectShell() == '.bashrc'):
if(ExtraTools == 1):
os.system('sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"')
elif(DetectShell() == '.zshrc'):
if(ExtraTools == 1):
os.system('sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"')

def UninstallScript():
try:
Bashrc=open(os.path.join(Home,".bashrc"),"w")
Shell=open(os.path.join(Home,DetectShell()),"w")
except IOError:
print("I Think Bashrc Is Write Protect, Fix It And Run Code Again")
print("I Think Shell Is Write Protect, Fix It And Run Code Again")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run this again, is better than run code

exit()
Bashrc.write(WithoutScript)
Bashrc.close()
Shell.write(WithoutScript)
Shell.close()
def FindVer(start,scriptstr):
endline="\n"
ListTmpVer=list()
Expand All @@ -347,18 +379,19 @@ def FindVer(start,scriptstr):
ListTmpVer.append(scriptstr[step])
step+=1
return int(''.join(ListTmpVer))
Bashrc=open(os.path.join(Home,".bashrc"),"r")
for line in Bashrc:

Shell=open(os.path.join(Home,DetectShell()),"r")
for line in Shell:
if (line=="#####AA Zone#####\n"):
TagCount+=1
Bashrc.close()
Shell.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"
omb="1.Oh My Bash"
bashit="2.Bashit"
omz = "1.Oh My Zsh"
iowt="0.None Of Them, AA is Enough"
donesad="Done :("
donehappy="Done :)"
wisechoice="Wise Choice :)"
Expand All @@ -367,28 +400,29 @@ def FindVer(start,scriptstr):
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"
newincompatver="Your Version Is Newer And Backward Incompatible Or You Have A Corrupt Version of AA In Your Shell,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) : "
resetshell="To Effect Changes You Need To Run A New Bash Or Source Shell, Do You Want To Source Shell? (If You Are Already Running This In Bash Its Recommended) (Yes/No) : "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a new bash or source shell XD? lets go with "a new shell or source your shell dotfile", same next line


if (TagCount==0):
ans=yesno(angryinput(letsinstall,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
InstallExtra()
print(donehappy)
elif (TagCount==1):
ans=yesno(angryinput(pbbutinstalled,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
print(donehappy)
elif (TagCount==2):
if (('\n'+InstalledScript+'\n')==Script):
Expand All @@ -401,7 +435,7 @@ def FindVer(start,scriptstr):
UninstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
print(donesad)
else:
print(wisechoice)
Expand All @@ -424,22 +458,22 @@ def FindVer(start,scriptstr):
UninstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
print(donesad)
if (ans2==2):
UninstallScript()
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
print(donehappy)
else:
ans=yesno(angryinput(pbbutinstalled,func=yesno))
if (ans):
InstallScript()
ansreset=yesno(angryinput(resetshell,func=yesno))
if (ansreset):
ResetBash()
ResetShell()
print(donehappy)

print(end + "\033[2J" + "\033[1;1H")
Expand Down