Skip to content

Commit

Permalink
Better shell integration
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Nov 14, 2024
1 parent 55db632 commit fa26518
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
4 changes: 2 additions & 2 deletions interpreter_1/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ async def async_load():
pass
print()

# if interpreter.interactive:
# interpreter.chat() # Continue in interactive mode
if interpreter.interactive:
interpreter.chat() # Continue in interactive mode


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
i = "interpreter_1.cli:main"
interpreter = "interpreter_1.cli:main"
interpreter-shell = "scripts.shell:main"

wtf = "scripts.wtf:main"
interpreter-classic = "interpreter.terminal_interface.start_terminal_interface:main"
Expand Down
52 changes: 46 additions & 6 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,52 @@ fi

# Platform-specific final instructions
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
info "Installation complete! You can now use 'open-interpreter' from a new terminal window."
info "Installation complete! You can now use 'interpreter' from a new terminal window."
elif [[ "$OSTYPE" == "darwin"* ]]; then
info "Installation complete! You can now use the 'open-interpreter' command."
info "Make sure $BIN_DIR is in your PATH by adding this to your ~/.zshrc or ~/.bash_profile:"
info " export PATH=\"\$PATH:$BIN_DIR\""
info "Installation complete! You can now use the 'interpreter' command."
info "Would you like to add $BIN_DIR to your PATH? [y/N] "
read -r add_to_path
if [[ "$add_to_path" =~ ^[Yy]$ ]]; then
if [[ -f "$HOME/.zshrc" ]]; then
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.zshrc"
info "Added to ~/.zshrc. Please restart your terminal or run: source ~/.zshrc"
elif [[ -f "$HOME/.bash_profile" ]]; then
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.bash_profile"
info "Added to ~/.bash_profile. Please restart your terminal or run: source ~/.bash_profile"
else
info "Could not find ~/.zshrc or ~/.bash_profile. Please manually add to your shell's config:"
info " export PATH=\"\$PATH:$BIN_DIR\""
fi
else
info "You can manually add $BIN_DIR to your PATH by adding this to ~/.zshrc or ~/.bash_profile:"
info " export PATH=\"\$PATH:$BIN_DIR\""
fi
else
info "Installation complete! You can now use the 'open-interpreter' command."
info "Make sure $BIN_DIR is in your PATH."
info "Installation complete! You can now use the 'interpreter' command."
info "Would you like to add $BIN_DIR to your PATH? [y/N] "
read -r add_to_path
if [[ "$add_to_path" =~ ^[Yy]$ ]]; then
if [[ -f "$HOME/.bashrc" ]]; then
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.bashrc"
info "Added to ~/.bashrc. Please restart your terminal or run: source ~/.bashrc"
else
info "Could not find ~/.bashrc. Please manually add to your shell's config:"
info " export PATH=\"\$PATH:$BIN_DIR\""
fi
else
info "You can manually add $BIN_DIR to your PATH by adding this to ~/.bashrc:"
info " export PATH=\"\$PATH:$BIN_DIR\""
fi
fi

# Offer shell integration
info "Would you like to install shell integration? This allows you to use Open Interpreter directly from your shell - if you type an unrecognized command, it will be passed to Open Interpreter with context about your recent shell history. [y/N] "
read -r install_shell_integration
if [[ "$install_shell_integration" =~ ^[Yy]$ ]]; then
if command_exists interpreter-shell; then
interpreter-shell
info "Shell integration installed successfully! Restart your shell to activate it."
else
error "Could not find interpreter-shell command. Please ensure Open Interpreter was installed correctly."
fi
fi
12 changes: 8 additions & 4 deletions scripts/setup.py → scripts/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_shell_config():

def get_shell_script(shell_type):
"""Return the appropriate shell script based on shell type."""
base_script = """# Create log file if it doesn't exist
base_script = r"""# Create log file if it doesn't exist
touch ~/.shell_history_with_output
# Function to capture terminal interaction
Expand Down Expand Up @@ -68,11 +68,12 @@ def get_shell_script(shell_type):
# Command not found handler that pipes context to interpreter
command_not_found_handler() {
local cmd=$1
# echo "user: $cmd" >> ~/.shell_history_with_output
# echo "computer:" >> ~/.shell_history_with_output
# Capture output in temp file, display unstripped version, then process and append stripped version
output_file=$(mktemp)
# 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 | \
tee "$output_file"
cat "$output_file" | sed -r \
Expand All @@ -82,7 +83,10 @@ def get_shell_script(shell_type):
-e "s/^[[:space:]\.]*//;s/[[:space:]\.]*$//" \
-e "s/─{3,}//g" \
>> ~/.shell_history_with_output
rm "$output_file"
# Clean up and remove the trap
trap - INT
rm -f "$output_file"
return 0
}
Expand Down

0 comments on commit fa26518

Please sign in to comment.