-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert-variables.sh
executable file
·55 lines (44 loc) · 1.93 KB
/
insert-variables.sh
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
#!/bin/bash
# --- Get Environment Variables Correctly ---
if [[ "$(uname)" == "Darwin" ]]; then
# macOS specific
OS="macOS $(sw_vers -productVersion)"
SED_IN_PLACE=(-i "")
else
# Linux specific
OS=$(uname -s -r)
SED_IN_PLACE=(-i)
fi
SHELL="bash" # Hardcode to bash since we're explicitly using it
HOME=$(echo "$HOME") # Use existing $HOME, but quote it
WORKSPACE=$(pwd)
# --- Construct Paths ---
GLOBAL_SETTINGS="$HOME/.vscode-server/data/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_custom_modes.json"
MCP_LOCATION="$HOME/.local/share/Roo-Code/MCP"
MCP_SETTINGS="$HOME/.vscode-server/data/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json"
# --- Directory Setup ---
ROO_DIR="$WORKSPACE/.roo"
# Check if the .roo directory exists
if [ ! -d "$ROO_DIR" ]; then
echo "Error: .roo directory not found in $WORKSPACE"
exit 1
fi
# --- Function to escape strings for sed ---
escape_for_sed() {
echo "$1" | sed 's/[\/&]/\\&/g'
}
# --- Perform Replacements using sed ---
find "$ROO_DIR" -type f -name "system-prompt-*" -print0 | while IFS= read -r -d $'\0' file; do
echo "Processing: $file"
# Basic variables - using sed with escaped strings
sed "${SED_IN_PLACE[@]}" "s/OS_PLACEHOLDER/$(escape_for_sed "$OS")/g" "$file"
sed "${SED_IN_PLACE[@]}" "s/SHELL_PLACEHOLDER/$(escape_for_sed "$SHELL")/g" "$file"
sed "${SED_IN_PLACE[@]}" "s|HOME_PLACEHOLDER|$(escape_for_sed "$HOME")|g" "$file"
sed "${SED_IN_PLACE[@]}" "s|WORKSPACE_PLACEHOLDER|$(escape_for_sed "$WORKSPACE")|g" "$file"
# Complex paths - using sed with escaped strings
sed "${SED_IN_PLACE[@]}" "s|GLOBAL_SETTINGS_PLACEHOLDER|$(escape_for_sed "$GLOBAL_SETTINGS")|g" "$file"
sed "${SED_IN_PLACE[@]}" "s|MCP_LOCATION_PLACEHOLDER|$(escape_for_sed "$MCP_LOCATION")|g" "$file"
sed "${SED_IN_PLACE[@]}" "s|MCP_SETTINGS_PLACEHOLDER|$(escape_for_sed "$MCP_SETTINGS")|g" "$file"
echo "Completed: $file"
done
echo "Done."