mirror of https://github.com/ashikslab/smartsh.git
add SMARTSH_COLORIZE_OUTPUT and SMARTSH_TUNE_FOR_POWERSHELL support
This commit is contained in:
parent
dadc4ac21b
commit
5bf78b2e9a
20
smartsh.py
20
smartsh.py
|
@ -18,7 +18,8 @@ if api_model is None:
|
||||||
print("Using default model " + api_model)
|
print("Using default model " + api_model)
|
||||||
|
|
||||||
smarsh_debug_mode = os.environ.get("SMARTSH_DEBUG")
|
smarsh_debug_mode = os.environ.get("SMARTSH_DEBUG")
|
||||||
|
tune_for_powershell = os.environ.get("SMARTSH_TUNE_FOR_POWERSHELL") == "1" or os.environ.get("SMARTSH_TUNE_FOR_POWERSHELL") == "true"
|
||||||
|
colorize_output = os.environ.get("SMARTSH_COLORIZE_OUTPUT") == "1" or os.environ.get("SMARTSH_COLORIZE_OUTPUT") == "true"
|
||||||
is_in_teacher_mode = False
|
is_in_teacher_mode = False
|
||||||
smartsh_teacher_mode = os.environ.get("SMARTSH_TEACHER_MODE")
|
smartsh_teacher_mode = os.environ.get("SMARTSH_TEACHER_MODE")
|
||||||
if smartsh_teacher_mode == "1" or smartsh_teacher_mode == "true":
|
if smartsh_teacher_mode == "1" or smartsh_teacher_mode == "true":
|
||||||
|
@ -36,8 +37,14 @@ if smarsh_debug_mode == "1" or smarsh_debug_mode == "true":
|
||||||
argcmd = " ".join(sys.argv)
|
argcmd = " ".join(sys.argv)
|
||||||
prompttxt = ""
|
prompttxt = ""
|
||||||
if is_in_teacher_mode:
|
if is_in_teacher_mode:
|
||||||
|
if tune_for_powershell:
|
||||||
|
prompttxt = "You suggest a valid PowerShell command to accomplish the following, together with an explanation: " + argcmd
|
||||||
|
else:
|
||||||
prompttxt = "You suggest a valid shell command to accomplish the following, together with an explanation: " + argcmd
|
prompttxt = "You suggest a valid shell command to accomplish the following, together with an explanation: " + argcmd
|
||||||
else:
|
else:
|
||||||
|
if tune_for_powershell:
|
||||||
|
prompttxt = "You suggest a valid and correct PowerShell command to accomplish the following. You shall not provide any further explanation or additional text: " + argcmd
|
||||||
|
else:
|
||||||
prompttxt = "You suggest a valid and correct {os.environ.get('SHELL')} command to accomplish the following. You shall not provide any further explanation or additional text: " + argcmd
|
prompttxt = "You suggest a valid and correct {os.environ.get('SHELL')} command to accomplish the following. You shall not provide any further explanation or additional text: " + argcmd
|
||||||
completion = None
|
completion = None
|
||||||
apioutput = None
|
apioutput = None
|
||||||
|
@ -68,12 +75,21 @@ elif api_model == "gpt-3.5-turbo":
|
||||||
|
|
||||||
# Ask the user if the suggested command shall be executed
|
# Ask the user if the suggested command shall be executed
|
||||||
if is_in_teacher_mode == False and apioutput is not None:
|
if is_in_teacher_mode == False and apioutput is not None:
|
||||||
print("Suggested command: " + apioutput)
|
# print the suggested command in bright red
|
||||||
|
if colorize_output:
|
||||||
|
print("suggested command: \033[91m" + apioutput + "\033[0m")
|
||||||
|
else:
|
||||||
|
print("suggested command: " + apioutput)
|
||||||
|
|
||||||
print("Do you want to execute this command? (y/n)")
|
print("Do you want to execute this command? (y/n)")
|
||||||
user_input = input()
|
user_input = input()
|
||||||
if user_input == 'y':
|
if user_input == 'y':
|
||||||
print("Executing command: " + apioutput)
|
print("Executing command: " + apioutput)
|
||||||
|
if colorize_output:
|
||||||
|
print("\033[93m")
|
||||||
os.system(apioutput)
|
os.system(apioutput)
|
||||||
|
if colorize_output:
|
||||||
|
print("\033[0m")
|
||||||
else:
|
else:
|
||||||
print("Command not executed")
|
print("Command not executed")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue