#!/bin/bash # CLI Command Memory - Shell Integration Setup # Run this script to set up shell integration for auto-recording set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CLI_MEMORY_HOME="${CLI_MEMORY_HOME:-$HOME/.cli_memory}" SHELL_DIR="$CLI_MEMORY_HOME/shell" echo "Setting up CLI Command Memory shell integration..." echo "=================================================" mkdir -p "$SHELL_DIR" cp "$SCRIPT_DIR/bash_completion.sh" "$SHELL_DIR/" PROFILE_FILE="" if [[ -f "$HOME/.bashrc" ]]; then PROFILE_FILE="$HOME/.bashrc" elif [[ -f "$HOME/.bash_profile" ]]; then PROFILE_FILE="$HOME/.bash_profile" elif [[ -f "$HOME/.profile" ]]; then PROFILE_FILE="$HOME/.profile" fi COMPLETION_LINE="source $SHELL_DIR/bash_completion.sh" PROMPT_COMMAND_LINE='export PROMPT_COMMAND="${PROMPT_COMMAND}:$(cm-prompt)"' if [[ -n "$PROFILE_FILE" ]]; then if ! grep -q "cli-memory" "$PROFILE_FILE" 2>/dev/null; then echo "" >> "$PROFILE_FILE" echo "# CLI Command Memory" >> "$PROFILE_FILE" echo "$COMPLETION_LINE" >> "$PROFILE_FILE" echo "$PROMPT_COMMAND_LINE" >> "$PROFILE_FILE" echo "Added shell integration to $PROFILE_FILE" else echo "Shell integration already configured in $PROFILE_FILE" fi else echo "Could not find shell profile file. Please add the following to your shell profile:" echo "" echo "$COMPLETION_LINE" echo "$PROMPT_COMMAND_LINE" fi echo "" echo "Setup complete!" echo "" echo "To use the shell integration:" echo " 1. Restart your shell: source ~/.bashrc" echo " 2. Start recording: cli-memory record start" echo " 3. Commands will be automatically captured"