Skip to content

Commit fa26518

Browse files
committed
Better shell integration
1 parent 55db632 commit fa26518

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

interpreter_1/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ async def async_load():
252252
pass
253253
print()
254254

255-
# if interpreter.interactive:
256-
# interpreter.chat() # Continue in interactive mode
255+
if interpreter.interactive:
256+
interpreter.chat() # Continue in interactive mode
257257

258258

259259
if __name__ == "__main__":

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ build-backend = "poetry.core.masonry.api"
3333
[tool.poetry.scripts]
3434
i = "interpreter_1.cli:main"
3535
interpreter = "interpreter_1.cli:main"
36+
interpreter-shell = "scripts.shell:main"
3637

3738
wtf = "scripts.wtf:main"
3839
interpreter-classic = "interpreter.terminal_interface.start_terminal_interface:main"

scripts/install.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,52 @@ fi
141141

142142
# Platform-specific final instructions
143143
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
144-
info "Installation complete! You can now use 'open-interpreter' from a new terminal window."
144+
info "Installation complete! You can now use 'interpreter' from a new terminal window."
145145
elif [[ "$OSTYPE" == "darwin"* ]]; then
146-
info "Installation complete! You can now use the 'open-interpreter' command."
147-
info "Make sure $BIN_DIR is in your PATH by adding this to your ~/.zshrc or ~/.bash_profile:"
148-
info " export PATH=\"\$PATH:$BIN_DIR\""
146+
info "Installation complete! You can now use the 'interpreter' command."
147+
info "Would you like to add $BIN_DIR to your PATH? [y/N] "
148+
read -r add_to_path
149+
if [[ "$add_to_path" =~ ^[Yy]$ ]]; then
150+
if [[ -f "$HOME/.zshrc" ]]; then
151+
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.zshrc"
152+
info "Added to ~/.zshrc. Please restart your terminal or run: source ~/.zshrc"
153+
elif [[ -f "$HOME/.bash_profile" ]]; then
154+
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.bash_profile"
155+
info "Added to ~/.bash_profile. Please restart your terminal or run: source ~/.bash_profile"
156+
else
157+
info "Could not find ~/.zshrc or ~/.bash_profile. Please manually add to your shell's config:"
158+
info " export PATH=\"\$PATH:$BIN_DIR\""
159+
fi
160+
else
161+
info "You can manually add $BIN_DIR to your PATH by adding this to ~/.zshrc or ~/.bash_profile:"
162+
info " export PATH=\"\$PATH:$BIN_DIR\""
163+
fi
149164
else
150-
info "Installation complete! You can now use the 'open-interpreter' command."
151-
info "Make sure $BIN_DIR is in your PATH."
165+
info "Installation complete! You can now use the 'interpreter' command."
166+
info "Would you like to add $BIN_DIR to your PATH? [y/N] "
167+
read -r add_to_path
168+
if [[ "$add_to_path" =~ ^[Yy]$ ]]; then
169+
if [[ -f "$HOME/.bashrc" ]]; then
170+
echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$HOME/.bashrc"
171+
info "Added to ~/.bashrc. Please restart your terminal or run: source ~/.bashrc"
172+
else
173+
info "Could not find ~/.bashrc. Please manually add to your shell's config:"
174+
info " export PATH=\"\$PATH:$BIN_DIR\""
175+
fi
176+
else
177+
info "You can manually add $BIN_DIR to your PATH by adding this to ~/.bashrc:"
178+
info " export PATH=\"\$PATH:$BIN_DIR\""
179+
fi
180+
fi
181+
182+
# Offer shell integration
183+
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] "
184+
read -r install_shell_integration
185+
if [[ "$install_shell_integration" =~ ^[Yy]$ ]]; then
186+
if command_exists interpreter-shell; then
187+
interpreter-shell
188+
info "Shell integration installed successfully! Restart your shell to activate it."
189+
else
190+
error "Could not find interpreter-shell command. Please ensure Open Interpreter was installed correctly."
191+
fi
152192
fi

scripts/setup.py renamed to scripts/shell.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_shell_config():
3838

3939
def get_shell_script(shell_type):
4040
"""Return the appropriate shell script based on shell type."""
41-
base_script = """# Create log file if it doesn't exist
41+
base_script = r"""# Create log file if it doesn't exist
4242
touch ~/.shell_history_with_output
4343
4444
# Function to capture terminal interaction
@@ -68,11 +68,12 @@ def get_shell_script(shell_type):
6868
# Command not found handler that pipes context to interpreter
6969
command_not_found_handler() {
7070
local cmd=$1
71-
# echo "user: $cmd" >> ~/.shell_history_with_output
72-
# echo "computer:" >> ~/.shell_history_with_output
7371
7472
# Capture output in temp file, display unstripped version, then process and append stripped version
7573
output_file=$(mktemp)
74+
# Add trap to handle SIGINT (Ctrl+C) gracefully
75+
trap "rm -f $output_file; return 0" INT
76+
7677
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 | \
7778
tee "$output_file"
7879
cat "$output_file" | sed -r \
@@ -82,7 +83,10 @@ def get_shell_script(shell_type):
8283
-e "s/^[[:space:]\.]*//;s/[[:space:]\.]*$//" \
8384
-e "s/─{3,}//g" \
8485
>> ~/.shell_history_with_output
85-
rm "$output_file"
86+
87+
# Clean up and remove the trap
88+
trap - INT
89+
rm -f "$output_file"
8690
return 0
8791
}
8892

0 commit comments

Comments
 (0)