-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_antigravity.sh
More file actions
174 lines (148 loc) · 5.35 KB
/
setup_antigravity.sh
File metadata and controls
174 lines (148 loc) · 5.35 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
#
# Antigravity R & Python Setup - Linux/macOS
# Based on VSCode Setup by Fr4nzz
#
set -euo pipefail
# --- CONFIGURATION ---
EDITOR_CMD="antigravity"
if [[ "$OSTYPE" == "darwin"* ]]; then
SETTINGS_DIR="$HOME/Library/Application Support/Antigravity/User"
else
SETTINGS_DIR="$HOME/.config/Antigravity/User"
fi
SETTINGS_FILE="$SETTINGS_DIR/settings.json"
# ---------------------
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
YELLOW='\033[1;33m'
# Defaults
INSTALL_R=true
INSTALL_PYTHON=true
INSTALL_RADIAN=true
R_PACKAGE_MANAGER="ppm"
# Parse Args
while [[ $# -gt 0 ]]; do
case $1 in
--r-only) INSTALL_R=true; INSTALL_PYTHON=false; shift ;;
--python-only) INSTALL_R=false; INSTALL_PYTHON=true; shift ;;
--skip-radian) INSTALL_RADIAN=false; shift ;;
--package-manager) R_PACKAGE_MANAGER="$2"; shift 2 ;;
*) shift ;;
esac
done
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
check_editor() {
if ! command_exists $EDITOR_CMD; then
log_error "Antigravity CLI ($EDITOR_CMD) not found."
log_error "Please install Antigravity manually and ensure 'antigravity' is in your PATH."
exit 1
fi
}
# --- REUSE INSTALLATION LOGIC ---
detect_system() {
OS="$(uname -s)"
ARCH="$(uname -m)"
if [[ "$OS" == "Linux"* ]]; then
if [ -f /etc/os-release ]; then . /etc/os-release; DISTRO="$ID"; DISTRO_CODENAME="${VERSION_CODENAME:-}"; fi
OS_TYPE="linux"
if [ "$ARCH" = "aarch64" ]; then ARCH_TYPE="arm64"; else ARCH_TYPE="x86_64"; fi
else
OS_TYPE="macos"
fi
}
install_env() {
log_info "Checking R and Python environment..."
if [ "$INSTALL_R" = true ] && ! command_exists R; then
log_error "R not found. Please run the main install.sh first or install R manually."
fi
if [ "$INSTALL_PYTHON" = true ] && ! command_exists python3; then
log_error "Python not found. Please run the main install.sh first or install Python manually."
fi
}
# --- ANTIGRAVITY CONFIG ---
configure_settings() {
MODE="$1" # "STANDARD" or "HACK"
mkdir -p "$SETTINGS_DIR"
if [ ! -f "$SETTINGS_FILE" ]; then echo '{}' > "$SETTINGS_FILE"; fi
if ! command_exists jq; then log_error "jq is required for this script."; exit 1; fi
TMP=$(mktemp)
# 1. Always set Antigravity Keys + Paths
# 2. If HACK mode, add extensions.gallery. If STANDARD, remove it.
if [ "$MODE" == "HACK" ]; then
# Add standard keys (Hack Mode)
jq '. + {
"extensions.gallery": {
"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
"cacheUrl": "https://marketplace.visualstudio.com/_apis/public/gallery/cache",
"itemUrl": "https://marketplace.visualstudio.com/items"
}
}' "$SETTINGS_FILE" > "$TMP" && mv "$TMP" "$SETTINGS_FILE"
else
# Remove standard keys (Standard Mode)
jq 'del(.["extensions.gallery"]) | . + {
"antigravity.marketplaceExtensionGalleryServiceURL": "https://marketplace.visualstudio.com/_apis/public/gallery",
"antigravity.marketplaceGalleryItemURL": "https://marketplace.visualstudio.com/items"
}' "$SETTINGS_FILE" > "$TMP" && mv "$TMP" "$SETTINGS_FILE"
fi
# Apply paths (idempotent)
if [ "$INSTALL_R" = true ]; then
RADIAN=$(command -v radian || echo "")
jq --arg radian "$RADIAN" '. + {
"r.rterm.linux": $radian,
"r.rterm.mac": $radian,
"r.plot.useHttpgd": true,
"r.bracketedPaste": true,
"r.sessionWatcher": true
}' "$SETTINGS_FILE" > "$TMP" && mv "$TMP" "$SETTINGS_FILE"
fi
if [ "$INSTALL_PYTHON" = true ]; then
PY=$(command -v python3)
jq --arg py "$PY" '. + {
"python.defaultInterpreterPath": $py,
"python.terminal.activateEnvironment": true
}' "$SETTINGS_FILE" > "$TMP" && mv "$TMP" "$SETTINGS_FILE"
fi
}
install_extensions() {
log_info "Configuring Marketplace..."
configure_settings "STANDARD"
EXTS=()
if [ "$INSTALL_R" = true ]; then EXTS+=("REditorSupport.r" "Posit.shiny" "RDebugger.r-debugger"); fi
if [ "$INSTALL_PYTHON" = true ]; then EXTS+=("ms-python.python@2025.18.0" "ms-toolsai.jupyter@2025.8.0"); fi
HACK_ACTIVE=false
for ext in "${EXTS[@]}"; do
log_info "Installing $ext..."
# Attempt 1
if $EDITOR_CMD --install-extension "$ext" --force >/dev/null 2>&1; then
: # Success
else
# Failure detected, enable hack if not already active
if [ "$HACK_ACTIVE" = false ]; then
log_warn "CLI failed to find extension. Retrying with compatibility hack..."
configure_settings "HACK"
HACK_ACTIVE=true
fi
# Attempt 2 (With Hack)
$EDITOR_CMD --install-extension "$ext" --force >/dev/null 2>&1 || true
fi
done
log_info "Finalizing Settings..."
configure_settings "STANDARD"
log_success "Settings updated."
}
main() {
detect_system
check_editor
install_env
install_extensions
log_success "Antigravity Setup Complete."
}
main