|
| 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