From 8be32f90da65056fd6bd1339f887957919237a4e Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 10:57:47 +0000 Subject: [PATCH] Starting better version (And not whatever hacky version I first though of) --- install.sh | 31 +++++++++++++++++++++++++------ yolo.bat | 6 +++++- yolo.py | 11 +++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 2db7871..c98938f 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,31 @@ -# Installs yolo in the user's CMD directory ( change $CMD to desired file path ) +# Installs yolo in the user's home directory -TARGET_DIR=$CMD +TARGET_DIR=~/yolo-ai-cmdbot TARGET_FULLPATH=$TARGET_DIR/yolo.py mkdir -p $TARGET_DIR -cp yolo.py $TARGET_DIR -cp prompt.txt $TARGET_DIR/yolo_prompt.txt #changed this so it doesnt conflict with possible future prompts +cp yolo.py prompt.txt $TARGET_DIR chmod +x $TARGET_FULLPATH -# Adds batch file to System32 so you can call it in powershell -cp yolo.bat C:/Windows/System32 \ No newline at end of file +#Linux/Mac + +# Creates two aliases for use +alias yolo=$TARGET_FULLPATH +alias computer=$TARGET_FULLPATH + +# Add the aliases to the logon scripts +echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases + +# Windows +# Copy yolo.bat to System32 or : + +# (This doesn't work, havent figured it out) + +# Creates two aliases for use +alias yolo=$TARGET_FULLPATH +alias computer=$TARGET_FULLPATH + +# Add the aliases to the logon scripts +echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.bat b/yolo.bat index 8eac22f..13fdc30 100644 --- a/yolo.bat +++ b/yolo.bat @@ -1,3 +1,7 @@ @echo off + +REM Work around to not have to type in python.exe yolo.py every time. +REM Put in C:/Windows/System32 to allow command to work anywhere + set /P "prompt=Enter Prompt: " -python.exe C:\Users\kause\Downloads\Commands\yolo.py %prompt% +python.exe ~/yolo-ai-cmdbot/yolo.py %prompt% diff --git a/yolo.py b/yolo.py index 226ec6e..b5664bd 100755 --- a/yolo.py +++ b/yolo.py @@ -12,8 +12,6 @@ import subprocess from termcolor import colored from colorama import init -import dotenv - # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -34,7 +32,7 @@ def get_full_prompt(user_prompt, shell): prompt_path = os.path.dirname(yolo_path) ## Load the prompt and prep it - prompt_file = os.path.join(prompt_path, "yolo_prompt.txt") + prompt_file = os.path.join(prompt_path, "prompt.txt") pre_prompt = open(prompt_file,"r").read() pre_prompt = pre_prompt.replace("{shell}", shell) pre_prompt = pre_prompt.replace("{os}", get_os_friendly_name()) @@ -80,9 +78,10 @@ if __name__ == "__main__": ask_flag = False # safety switch -a command line argument yolo = "" # user's answer to safety switch (-a) question y/n - # Presumes the folder yolo.py is copied to has a .env - dotenv.load_dotenv(".env") + # Two options for the user to specify they openai api key + home_path = os.path.expanduser("~") openai.api_key = os.getenv("OPENAI_API_KEY") + openai.api_key_path = os.path.join(home_path,".openai.apikey") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: @@ -154,4 +153,4 @@ if yolo == "Y" or yolo == "": subprocess.run([shell, "/c", res_command], shell=False) else: # Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not - subprocess.run([shell, "-c", res_command], shell=False) \ No newline at end of file + subprocess.run([shell, "-c", res_command], shell=False)