diff --git a/aa.py b/aa.py index b108502..363fcd7 100644 --- a/aa.py +++ b/aa.py @@ -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''' ___ ___ / \ / \ @@ -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] @@ -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") exit() - Bashrc.write(WithoutScript) - Bashrc.close() + Shell.write(WithoutScript) + Shell.close() def FindVer(start,scriptstr): endline="\n" ListTmpVer=list() @@ -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 :)" @@ -367,12 +400,12 @@ 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) : " if (TagCount==0): ans=yesno(angryinput(letsinstall,func=yesno)) @@ -380,7 +413,8 @@ def FindVer(start,scriptstr): InstallScript() ansreset=yesno(angryinput(resetshell,func=yesno)) if (ansreset): - ResetBash() + ResetShell() + InstallExtra() print(donehappy) elif (TagCount==1): ans=yesno(angryinput(pbbutinstalled,func=yesno)) @@ -388,7 +422,7 @@ def FindVer(start,scriptstr): InstallScript() ansreset=yesno(angryinput(resetshell,func=yesno)) if (ansreset): - ResetBash() + ResetShell() print(donehappy) elif (TagCount==2): if (('\n'+InstalledScript+'\n')==Script): @@ -401,7 +435,7 @@ def FindVer(start,scriptstr): UninstallScript() ansreset=yesno(angryinput(resetshell,func=yesno)) if (ansreset): - ResetBash() + ResetShell() print(donesad) else: print(wisechoice) @@ -424,14 +458,14 @@ 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)) @@ -439,7 +473,7 @@ def FindVer(start,scriptstr): InstallScript() ansreset=yesno(angryinput(resetshell,func=yesno)) if (ansreset): - ResetBash() + ResetShell() print(donehappy) print(end + "\033[2J" + "\033[1;1H")