Skip to content

Commit c0bc124

Browse files
committed
Restored wtf, added shell uninstall
1 parent fa26518 commit c0bc124

File tree

5 files changed

+597
-10
lines changed

5 files changed

+597
-10
lines changed

archive/wtf.py

Whitespace-only changes.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ screeninfo = "^0.8.1"
2525
readchar = "^4.2.1"
2626
pillow = "^11.0.0"
2727
uvicorn = "^0.32.0"
28+
pynput = "^1.7.7"
2829

2930
[build-system]
3031
requires = ["poetry-core>=1.0.0"]
@@ -33,7 +34,9 @@ build-backend = "poetry.core.masonry.api"
3334
[tool.poetry.scripts]
3435
i = "interpreter_1.cli:main"
3536
interpreter = "interpreter_1.cli:main"
37+
3638
interpreter-shell = "scripts.shell:main"
39+
interpreter-uninstall-shell = "scripts.uninstall_shell:main"
3740

3841
wtf = "scripts.wtf:main"
3942
interpreter-classic = "interpreter.terminal_interface.start_terminal_interface:main"

scripts/shell.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def get_shell_script(shell_type):
4444
# Function to capture terminal interaction
4545
function capture_output() {
4646
local cmd=$1
47-
# Redirect with more thorough ANSI and cursor control stripping
48-
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))
49-
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))
47+
# Use LC_ALL=C to force ASCII output and handle encoding issues
48+
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))
49+
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))
5050
5151
echo "user: $cmd" >> ~/.shell_history_with_output
5252
echo "computer:" >> ~/.shell_history_with_output
@@ -74,14 +74,16 @@ def get_shell_script(shell_type):
7474
# Add trap to handle SIGINT (Ctrl+C) gracefully
7575
trap "rm -f $output_file; return 0" INT
7676
77-
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 | \
77+
# Force ASCII output and clean non-printable characters
78+
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 | \
7879
tee "$output_file"
79-
cat "$output_file" | sed -r \
80-
-e "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGKHF]//g" \
81-
-e "s/\x1B\[[0-9;]*[A-Za-z]//g" \
82-
-e "s/\]633;[^]]*\]//g" \
83-
-e "s/^[[:space:]\.]*//;s/[[:space:]\.]*$//" \
84-
-e "s/─{3,}//g" \
80+
LC_ALL=C cat "$output_file" | LC_ALL=C sed \
81+
-e $'s/\x1B\[[0-9;]*[a-zA-Z]//g' \
82+
-e $'s/\x1B\[[0-9;]*[mGKHF]//g' \
83+
-e $'s/\]633;[^]]*\]//g' \
84+
-e 's/^[[:space:]\.]*//;s/[[:space:]\.]*$//' \
85+
-e 's/─\{3,\}//g' \
86+
-e $'s/[^[:print:]\t\n]//g' \
8587
>> ~/.shell_history_with_output
8688
8789
# Clean up and remove the trap

scripts/uninstall_shell.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Shell Integration Uninstaller for Open Interpreter
3+
4+
This script removes the shell integration previously installed by shell.py
5+
by removing the content between the marker comments in the shell config file.
6+
"""
7+
8+
import os
9+
import re
10+
from pathlib import Path
11+
12+
13+
def get_shell_config():
14+
"""Determine user's shell and return the appropriate config file path."""
15+
shell = os.environ.get("SHELL", "").lower()
16+
home = str(Path.home())
17+
18+
if "zsh" in shell:
19+
return os.path.join(home, ".zshrc")
20+
elif "bash" in shell:
21+
bash_rc = os.path.join(home, ".bashrc")
22+
bash_profile = os.path.join(home, ".bash_profile")
23+
24+
if os.path.exists(bash_rc):
25+
return bash_rc
26+
elif os.path.exists(bash_profile):
27+
return bash_profile
28+
29+
return None
30+
31+
32+
def main():
33+
"""Remove the shell integration."""
34+
print("Starting uninstallation...")
35+
config_path = get_shell_config()
36+
37+
if not config_path:
38+
print("Could not determine your shell configuration.")
39+
return
40+
41+
# Read existing config
42+
try:
43+
with open(config_path, "r") as f:
44+
content = f.read()
45+
except FileNotFoundError:
46+
print(f"Config file {config_path} not found.")
47+
return
48+
49+
start_marker = "### <openinterpreter> ###"
50+
end_marker = "### </openinterpreter> ###"
51+
52+
# Check if markers exist
53+
if start_marker not in content:
54+
print("Open Interpreter shell integration not found in config file.")
55+
return
56+
57+
# Remove the shell integration section
58+
pattern = f"{start_marker}.*?{end_marker}"
59+
new_content = re.sub(pattern, "", content, flags=re.DOTALL)
60+
61+
# Clean up any extra blank lines
62+
new_content = re.sub(r"\n\s*\n\s*\n", "\n\n", new_content)
63+
64+
# Write back to config file
65+
try:
66+
with open(config_path, "w") as f:
67+
f.write(new_content)
68+
print(
69+
f"Successfully removed Open Interpreter shell integration from {config_path}"
70+
)
71+
print("Please restart your shell for changes to take effect.")
72+
73+
# Remove history file if it exists
74+
history_file = os.path.expanduser("~/.shell_history_with_output")
75+
if os.path.exists(history_file):
76+
os.remove(history_file)
77+
print("Removed shell history file.")
78+
79+
except Exception as e:
80+
print(f"Error writing to {config_path}: {e}")
81+
82+
83+
if __name__ == "__main__":
84+
main()

0 commit comments

Comments
 (0)