Skip to content

Commit

Permalink
Restored wtf, added shell uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Nov 14, 2024
1 parent fa26518 commit c0bc124
Show file tree
Hide file tree
Showing 5 changed files with 597 additions and 10 deletions.
Empty file removed archive/wtf.py
Empty file.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ screeninfo = "^0.8.1"
readchar = "^4.2.1"
pillow = "^11.0.0"
uvicorn = "^0.32.0"
pynput = "^1.7.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -33,7 +34,9 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
i = "interpreter_1.cli:main"
interpreter = "interpreter_1.cli:main"

interpreter-shell = "scripts.shell:main"
interpreter-uninstall-shell = "scripts.uninstall_shell:main"

wtf = "scripts.wtf:main"
interpreter-classic = "interpreter.terminal_interface.start_terminal_interface:main"
Expand Down
22 changes: 12 additions & 10 deletions scripts/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def get_shell_script(shell_type):
# Function to capture terminal interaction
function capture_output() {
local cmd=$1
# Redirect with more thorough ANSI and cursor control stripping
exec 1> >(tee >(sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGKHF]//g; s/\x1B\[[0-9;]*[A-Za-z]//g; s/\r//g" >> ~/.shell_history_with_output))
exec 2> >(tee >(sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGKHF]//g; s/\x1B\[[0-9;]*[A-Za-z]//g; s/\r//g" >> ~/.shell_history_with_output))
# Use LC_ALL=C to force ASCII output and handle encoding issues
exec 1> >(LC_ALL=C tee >(LC_ALL=C sed -e $'s/\x1B\[[0-9;]*[a-zA-Z]//g' -e $'s/\x1B\[[0-9;]*[mGKHF]//g' -e $'s/[^[:print:]\t\n]//g' >> ~/.shell_history_with_output))
exec 2> >(LC_ALL=C tee >(LC_ALL=C sed -e $'s/\x1B\[[0-9;]*[a-zA-Z]//g' -e $'s/\x1B\[[0-9;]*[mGKHF]//g' -e $'s/[^[:print:]\t\n]//g' >> ~/.shell_history_with_output))
echo "user: $cmd" >> ~/.shell_history_with_output
echo "computer:" >> ~/.shell_history_with_output
Expand Down Expand Up @@ -74,14 +74,16 @@ def get_shell_script(shell_type):
# Add trap to handle SIGINT (Ctrl+C) gracefully
trap "rm -f $output_file; return 0" INT
interpreter --input "$(cat ~/.shell_history_with_output)" --instructions "You are in FAST mode. Be ultra-concise. Determine what the user is trying to do (most recently) and help them." 2>&1 | \
# Force ASCII output and clean non-printable characters
LC_ALL=C interpreter --input "$(cat ~/.shell_history_with_output)" --instructions "You are in FAST mode. Be ultra-concise. Determine what the user is trying to do (most recently) and help them." 2>&1 | \
tee "$output_file"
cat "$output_file" | sed -r \
-e "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGKHF]//g" \
-e "s/\x1B\[[0-9;]*[A-Za-z]//g" \
-e "s/\]633;[^]]*\]//g" \
-e "s/^[[:space:]\.]*//;s/[[:space:]\.]*$//" \
-e "s/─{3,}//g" \
LC_ALL=C cat "$output_file" | LC_ALL=C sed \
-e $'s/\x1B\[[0-9;]*[a-zA-Z]//g' \
-e $'s/\x1B\[[0-9;]*[mGKHF]//g' \
-e $'s/\]633;[^]]*\]//g' \
-e 's/^[[:space:]\.]*//;s/[[:space:]\.]*$//' \
-e 's/─\{3,\}//g' \
-e $'s/[^[:print:]\t\n]//g' \
>> ~/.shell_history_with_output
# Clean up and remove the trap
Expand Down
84 changes: 84 additions & 0 deletions scripts/uninstall_shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Shell Integration Uninstaller for Open Interpreter
This script removes the shell integration previously installed by shell.py
by removing the content between the marker comments in the shell config file.
"""

import os
import re
from pathlib import Path


def get_shell_config():
"""Determine user's shell and return the appropriate config file path."""
shell = os.environ.get("SHELL", "").lower()
home = str(Path.home())

if "zsh" in shell:
return os.path.join(home, ".zshrc")
elif "bash" in shell:
bash_rc = os.path.join(home, ".bashrc")
bash_profile = os.path.join(home, ".bash_profile")

if os.path.exists(bash_rc):
return bash_rc
elif os.path.exists(bash_profile):
return bash_profile

return None


def main():
"""Remove the shell integration."""
print("Starting uninstallation...")
config_path = get_shell_config()

if not config_path:
print("Could not determine your shell configuration.")
return

# Read existing config
try:
with open(config_path, "r") as f:
content = f.read()
except FileNotFoundError:
print(f"Config file {config_path} not found.")
return

start_marker = "### <openinterpreter> ###"
end_marker = "### </openinterpreter> ###"

# Check if markers exist
if start_marker not in content:
print("Open Interpreter shell integration not found in config file.")
return

# Remove the shell integration section
pattern = f"{start_marker}.*?{end_marker}"
new_content = re.sub(pattern, "", content, flags=re.DOTALL)

# Clean up any extra blank lines
new_content = re.sub(r"\n\s*\n\s*\n", "\n\n", new_content)

# Write back to config file
try:
with open(config_path, "w") as f:
f.write(new_content)
print(
f"Successfully removed Open Interpreter shell integration from {config_path}"
)
print("Please restart your shell for changes to take effect.")

# Remove history file if it exists
history_file = os.path.expanduser("~/.shell_history_with_output")
if os.path.exists(history_file):
os.remove(history_file)
print("Removed shell history file.")

except Exception as e:
print(f"Error writing to {config_path}: {e}")


if __name__ == "__main__":
main()
Loading

0 comments on commit c0bc124

Please sign in to comment.