-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 2.0 aims simply to be a more polished version 1.0
- Loading branch information
Showing
11 changed files
with
295 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,75 @@ | ||
#this runs your .omnirc file | ||
exec(open('.omnirc.py').read()) | ||
|
||
#This section imports the dependent libraries | ||
import sys | ||
import subprocess | ||
import os | ||
import theme | ||
import options | ||
from rich.console import Console | ||
from rich.prompt import Prompt as prompt | ||
import shutil | ||
from importlib import reload | ||
from pathlib import Path | ||
import time | ||
|
||
#defines the login sequence | ||
def login(): | ||
f = open("password.txt", "r") | ||
lgin = (f.read()) | ||
usr = input("Please enter your Username: ") | ||
usr = (usr + "\n") | ||
pss = input("Now enter your Password: ") | ||
usrpss = (usr + pss) | ||
if lgin == usrpss: | ||
print("Correct!") | ||
else: | ||
print("Incorrect, try again!") | ||
login() | ||
|
||
#This section shows the splash logo | ||
logo = theme.logo | ||
if options.dologo == True: | ||
Console().print(logo) | ||
|
||
#This section checks if the setup has already been completed | ||
stpcmplt = (os.path.isfile("./password.txt")) | ||
|
||
#This section does the main setup | ||
if stpcmplt == (bool(False)): | ||
usrnm = input("Please assign a Username: ") | ||
psswrd = input("Please assign a Password: ") | ||
usrnm = (usrnm + "\n") | ||
lgn = (usrnm + psswrd) | ||
print("Writing Password...") | ||
f = open("password.txt", "w") | ||
f.write(lgn) | ||
f.close() | ||
print("Setup complete") | ||
exec(open('prompt.py').read()) | ||
else: | ||
#calls the login sequence | ||
if options.dologin == True: | ||
login() | ||
exec(open('prompt.py').read()) | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
#Changes Current directory to the OmniShell | ||
os.chdir(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
#Creates .omnirc.py if it doesn't exist | ||
if os.path.isfile("./.omnirc.py") == False: | ||
f = open(".omnirc.py", "w") | ||
f.close() | ||
|
||
#This runs your .omnirc file | ||
exec(open('.omnirc.py').read()) | ||
|
||
#This section imports the dependent libraries | ||
import sys | ||
import subprocess | ||
import os | ||
import options | ||
from rich.console import Console | ||
from rich.prompt import Prompt as prompt | ||
import shutil | ||
from importlib import reload | ||
from pathlib import Path | ||
import time | ||
from prompt_toolkit import prompt | ||
from prompt_toolkit import PromptSession | ||
from prompt_toolkit.history import FileHistory | ||
from prompt_toolkit.completion import NestedCompleter | ||
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory | ||
from prompt_toolkit.validation import Validator | ||
from prompt_toolkit.styles import Style | ||
import theme | ||
|
||
#Defines the login sequence | ||
def login(): | ||
f = open("password.txt", "r") | ||
lgin = (f.read()) | ||
usr = input("Please enter your Username: ") | ||
usr = (usr + "\n") | ||
pss = input("Now enter your Password: ") | ||
usrpss = (usr + pss) | ||
if str(lgin) == str(usrpss): | ||
print("Correct!") | ||
else: | ||
print("Incorrect, try again!") | ||
login() | ||
|
||
#This section shows the splash logo | ||
logo = theme.logo | ||
if options.dologo == True: | ||
Console().print(logo) | ||
|
||
#This section checks if the setup has already been completed | ||
stpcmplt = (os.path.isfile("./password.txt")) | ||
|
||
#This section does the main setup | ||
if stpcmplt == False and options.dologin == True: | ||
usrnm = input("Please assign a Username: ") | ||
psswrd = input("Please assign a Password: ") | ||
usrnm = (usrnm + "\n") | ||
lgn = (usrnm + psswrd) | ||
print("Writing Password...") | ||
f = open("password.txt", "w") | ||
f.write(lgn) | ||
f.close() | ||
print("Setup complete") | ||
else: | ||
#Calls the login sequence | ||
if options.dologin == True: | ||
login() | ||
|
||
#Runs the prompt file | ||
exec(open('prompt.py').read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#This file is made as an easy way for addons and other scripts to add user configurable variables/options | ||
|
||
dologin = False #this feature is just a proof of concept at the moment and provides basically no extra security | ||
dologin = False #This feature is just a proof of concept at the moment and provides basically no extra security | ||
dologo = True | ||
unixmode = False | ||
unixmode = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,139 @@ | ||
#loads theme and asks for input | ||
cmdno = Console().input(theme.prompt) | ||
reload(theme) | ||
prompt = (theme.prompt) | ||
|
||
#exits omnishell | ||
if cmdno.lower() == ("exit"): | ||
print("Bye, Bye") | ||
|
||
#show current directory | ||
elif cmdno == ("cdir"): | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
print(dir_path) | ||
exec(open('prompt.py').read()) | ||
|
||
#does nothing, just prints new prompt | ||
elif cmdno == (""): | ||
exec(open('prompt.py').read()) | ||
|
||
#runs different files and scripts | ||
else: | ||
#checks which file types exist in ./scripts/ | ||
filechkpy = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".py")) | ||
filechkbat = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".bat")) | ||
filechkexe = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".exe")) | ||
filechklnk = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".lnk")) | ||
|
||
#prioritises python files | ||
if filechkpy == (bool(True)): | ||
cmd = (cmdno + ".py") | ||
Console().print(prompt + "executing: " + cmd) | ||
exec(open("./scripts/" + cmdno + "/" + cmd).read()) | ||
exec(open('prompt.py').read()) | ||
|
||
#then .bat files | ||
elif filechkbat == (bool(True)) and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".bat") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
bat_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
Console().print(prompt + "executing: " + cmd) | ||
subprocess.call([bat_path]) | ||
exec(open('prompt.py').read()) | ||
|
||
#next .exe files | ||
elif filechkexe == (bool(True)) and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".exe") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
exe_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
Console().print(prompt + "executing: " + cmd) | ||
subprocess.call(exe_path) | ||
exec(open('prompt.py').read()) | ||
|
||
#last .lnk files (shortcuts) | ||
elif filechklnk == (bool(True)) and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".lnk") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
lnk_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
Console().print(prompt + "executing: " + cmd) | ||
os.startfile(lnk_path) | ||
exec(open('prompt.py').read()) | ||
|
||
#if no file exists, it will then try and run it as a shell command | ||
#Define the prompt function | ||
def main(cmdno, theme, os): | ||
try: | ||
#Loads theme | ||
reload(theme) | ||
prompt = (theme.prompt) | ||
|
||
#Exits omnishell | ||
if cmdno.lower() == ("exit"): | ||
print("Bye, Bye") | ||
exit() | ||
|
||
#Show current directory | ||
elif cmdno == ("cdir"): | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
print(dir_path) | ||
|
||
#Does nothing, just prints new prompt | ||
elif cmdno == (""): | ||
#Don't worry this isn't meant to do anything | ||
0 == 0 | ||
|
||
#Runs different files and scripts | ||
else: | ||
#Checks which file types exist in ./scripts/ | ||
filechkpy = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".py" )) | ||
altchkpy = (os.path.isfile("./scripts/" + cmdno + "/main.py" )) | ||
filechkbat = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".bat")) | ||
filechkexe = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".exe")) | ||
filechklnk = (os.path.isfile("./scripts/" + cmdno + "/" + cmdno + ".lnk")) | ||
|
||
#Gets the number of matching files | ||
filematches = 0 | ||
if filechkpy == True: | ||
filematches = filematches + 1 | ||
if altchkpy == True: | ||
filematches = filematches + 1 | ||
if filechkbat == True: | ||
filematches = filematches + 1 | ||
if filechkexe == True: | ||
filematches = filematches + 1 | ||
if filechklnk == True: | ||
filematches = filematches + 1 | ||
|
||
#Sets file conflict mode | ||
if filematches > 1: | ||
print("Looks like there is a file conflict") | ||
print(os.listdir("./scripts/" + cmdno + "/")) | ||
conflict = input("choose a file: ") | ||
else: | ||
conflict = False | ||
|
||
#Runs python files | ||
if filechkpy == (bool(True)) or altchkpy == (bool(True)) or conflict == (cmdno + ".py") or conflict == "main.py" : | ||
cmd = (cmdno + ".py") | ||
if altchkpy == (bool(True)) and conflict != (cmdno + ".py"): | ||
cmd = ("main.py") | ||
exec(open("./scripts/" + cmdno + "/" + cmd).read()) | ||
|
||
#Runs .bat files | ||
elif filechkbat == (bool(True)) or conflict == (cmdno + ".bat") and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".bat") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
bat_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
subprocess.call([bat_path]) | ||
|
||
#Runs .exe files | ||
elif filechkexe == (bool(True)) or conflict == (cmdno + ".exe") and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".exe") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
exe_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
subprocess.call(exe_path) | ||
|
||
#Runs .lnk files (shortcuts) | ||
elif filechklnk == (bool(True)) or conflict == (cmdno + ".lnk") and options.unixmode == (bool(False)): | ||
cmd = (cmdno + ".lnk") | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
lnk_path = os.path.join(dir_path, "scripts", cmdno, cmd) | ||
os.startfile(lnk_path) | ||
|
||
#If input begins with "p! " run as python code | ||
if cmdno[0:3] == ("p! "): | ||
exec(cmdno[3:]) | ||
|
||
#If input begins with "b! " run as bash | ||
elif cmdno[0:3] == ("b! "): | ||
os.system("/bin/bash -c " + cmdno[3:]) | ||
|
||
#If input begins with "z! " run as zsh | ||
elif cmdno[0:3] == ("z! "): | ||
os.system("/bin/zsh -c " + cmdno[3:]) | ||
|
||
#If input begins with "f! " run as fish | ||
elif cmdno[0:3] == ("f! "): | ||
os.system("/bin/fish -c " + cmdno[3:]) | ||
|
||
#If no file exists, it will then try and run it as a shell command | ||
else: | ||
os.system(cmdno) | ||
|
||
#If there is an error it prints it | ||
except Exception as errmess: | ||
print("Error", errmess) | ||
|
||
#Sets the autocomplete list to include: $PATH, native commands, and scripts | ||
completionlist = [] | ||
path = os.environ['PATH'] | ||
path = path.split(':') | ||
for i in range(len(path)): | ||
completionlist = completionlist + os.listdir(path[i]) | ||
completionlist = completionlist + os.listdir("./scripts/") + ['exit', 'cdir', 'p!', 'b!', 'z!', 'f!'] | ||
#Turns the list into a dictionary so that the completetion only happens on the first word, to reduce lag | ||
completiondict = {item: None for item in completionlist} | ||
completer = NestedCompleter.from_nested_dict(completiondict) | ||
|
||
#Defines the rules for what counts as a valid command | ||
def valcmd(text): | ||
#Spaces are valid | ||
if not text or text.isspace(): | ||
return True | ||
|
||
#If the first word is on the completion list then it is valid | ||
else: | ||
os.system(cmdno) | ||
exec(open('prompt.py').read()) | ||
text = text.split(maxsplit=1) | ||
return text[0] in completionlist | ||
|
||
#Sets the error for if a command is not valid | ||
cmdvalidator = Validator.from_callable( | ||
valcmd, | ||
error_message="Invalid Command", | ||
move_cursor_to_end=True, | ||
) | ||
|
||
#Sets the history file | ||
session = PromptSession(history=FileHistory("./.omnihistory")) | ||
|
||
#The prompt | ||
while True: | ||
main(session.prompt(theme.prompt, style=theme.style, validator=cmdvalidator, validate_while_typing=True, completer=completer, auto_suggest=AutoSuggestFromHistory()), theme, os) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.