-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·119 lines (98 loc) · 3.6 KB
/
install.sh
File metadata and controls
executable file
·119 lines (98 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
echo "🚀 Starting ContextRecall Installer..."
# --- 1. Check for Cargo ---
if ! command -v cargo &> /dev/null; then
echo "❌ Error: Rust (cargo) is not installed."
echo "Please install Rust first: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
fi
# --- 2. Install fzf if missing ---
if ! command -v fzf &> /dev/null; then
echo "🔍 fzf not found. Attempting to install..."
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
echo "🍺 Installing fzf via Homebrew..."
brew install fzf
else
echo "❌ Error: Homebrew not found. Please install fzf manually."
exit 1
fi
elif [ -f /etc/debian_version ]; then
echo "🐧 Installing fzf via apt..."
sudo apt-get update && sudo apt-get install -y fzf
elif [ -f /etc/fedora-release ]; then
echo "🎩 Installing fzf via dnf..."
sudo dnf install -y fzf
elif [ -f /etc/arch-release ]; then
echo "🏹 Installing fzf via pacman..."
sudo pacman -S --noconfirm fzf
else
echo "❌ Could not detect package manager. Please install 'fzf' manually."
exit 1
fi
else
echo "✅ fzf is already installed."
fi
# --- 3. Build and Install the Rust Binary ---
echo "🔨 Building and installing ContextRecall..."
cargo install --path . --force
# --- 4. Generate Shell Integration Script ---
INSTALL_DIR="$HOME/.contextrecall"
mkdir -p "$INSTALL_DIR"
INIT_SCRIPT="$INSTALL_DIR/init.zsh"
echo "📝 Generating shell integration at $INIT_SCRIPT..."
cat > "$INIT_SCRIPT" <<EOF
# ContextRecall Shell Integration
# Generated by install.sh
_contextrecall_hook() {
local exit_code=\$?
local last_cmd=\$(fc -ln -1)
# Trim whitespace
last_cmd="\${last_cmd#"${last_cmd%%[![:space:]]*}"}"
# Record in background
contextrecall record "\$last_cmd" --exit-code "\$exit_code" > /dev/null 2>&1 &!
}
contextrecall_search() {
# Check for fzf again just in case
if ! command -v fzf &> /dev/null; then
echo "ContextRecall Error: fzf not found"
return 1
fi
# Run search -> pipe to fzf -> capture output
# --height 40%: occupy 40% of screen
# --reverse: list top-down
# --header: show title
local selected_command=\$(contextrecall search | fzf --height 40% --reverse --header="Context History")
if [ -n "\$selected_command" ]; then
LBUFFER="\$selected_command"
fi
zle reset-prompt
}
# Register Hooks (Zsh specific)
autoload -Uz add-zsh-hook
add-zsh-hook precmd _contextrecall_hook
# Register Widget
zle -N contextrecall-history-widget contextrecall_search
bindkey '^R' contextrecall-history-widget
EOF
# --- 5. Update Shell Config ---
SHELL_CONFIG="$HOME/.zshrc"
# If user is using bash, switch to .bashrc (logic can be expanded, assuming zsh for MacOS default)
if [[ "$SHELL" == *"bash"* ]]; then
SHELL_CONFIG="$HOME/.bashrc"
echo "⚠️ Bash detected. Note: The generated init script is currently optimized for Zsh."
echo " You may need to adapt the hook logic for Bash."
fi
SOURCE_CMD="source $INIT_SCRIPT"
if grep -Fxq "$SOURCE_CMD" "$SHELL_CONFIG"; then
echo "✅ Shell configuration already contains ContextRecall."
else
echo "config: appending source command to $SHELL_CONFIG"
echo "" >> "$SHELL_CONFIG"
echo "# ContextRecall" >> "$SHELL_CONFIG"
echo "$SOURCE_CMD" >> "$SHELL_CONFIG"
fi
echo ""
echo "🎉 Installation Complete!"
echo "👉 Please restart your terminal or run: source $SHELL_CONFIG"