create-egregore 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/setup.js +63 -17
- package/package.json +1 -1
package/lib/setup.js
CHANGED
|
@@ -156,28 +156,74 @@ function registerInstance(slug, name, egregoreDir) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
async function installShellAlias(egregoreDir, ui) {
|
|
159
|
-
const script = path.join(egregoreDir, "bin", "ensure-shell-function.sh");
|
|
160
|
-
if (!fs.existsSync(script)) {
|
|
161
|
-
ui.warn("Shell alias script not found — add alias manually.");
|
|
162
|
-
return { aliasName: "egregore", profileFile: ".zshrc" };
|
|
163
|
-
}
|
|
164
159
|
try {
|
|
165
|
-
//
|
|
166
|
-
const
|
|
167
|
-
|
|
160
|
+
// Detect shell profile
|
|
161
|
+
const shell = path.basename(process.env.SHELL || "");
|
|
162
|
+
let profile;
|
|
163
|
+
if (shell === "zsh" && fs.existsSync(path.join(os.homedir(), ".zshrc"))) {
|
|
164
|
+
profile = path.join(os.homedir(), ".zshrc");
|
|
165
|
+
} else if (shell === "fish") {
|
|
166
|
+
profile = path.join(os.homedir(), ".config", "fish", "config.fish");
|
|
167
|
+
} else {
|
|
168
|
+
for (const f of [".bash_profile", ".bashrc", ".profile"]) {
|
|
169
|
+
const p = path.join(os.homedir(), f);
|
|
170
|
+
if (fs.existsSync(p)) { profile = p; break; }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!profile) {
|
|
174
|
+
profile = path.join(os.homedir(), `.${shell || "bash"}rc`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const profileFile = path.basename(profile);
|
|
178
|
+
const aliasCmd = `cd "${egregoreDir}" && claude start`;
|
|
179
|
+
const profileContent = fs.existsSync(profile) ? fs.readFileSync(profile, "utf-8") : "";
|
|
180
|
+
|
|
181
|
+
// Check if this directory already has an alias
|
|
182
|
+
let existing = "";
|
|
183
|
+
if (profileContent.includes(egregoreDir)) {
|
|
184
|
+
const match = profileContent.match(new RegExp(`^alias ([^=]+)='[^']*${egregoreDir.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, "m"));
|
|
185
|
+
if (match) existing = match[1];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Recommend a name
|
|
189
|
+
let defaultName;
|
|
190
|
+
if (existing) {
|
|
191
|
+
defaultName = existing;
|
|
192
|
+
} else if (!profileContent.match(/^alias egregore=/m)) {
|
|
193
|
+
defaultName = "egregore";
|
|
194
|
+
} else {
|
|
195
|
+
// Read slug from egregore.json in the cloned repo
|
|
196
|
+
const configPath = path.join(egregoreDir, "egregore.json");
|
|
197
|
+
let slug = "";
|
|
198
|
+
if (fs.existsSync(configPath)) {
|
|
199
|
+
try { slug = JSON.parse(fs.readFileSync(configPath, "utf-8")).slug || ""; } catch {}
|
|
200
|
+
}
|
|
201
|
+
defaultName = slug ? `egregore-${slug}` : "egregore-2";
|
|
202
|
+
}
|
|
168
203
|
|
|
169
|
-
// Ask user
|
|
204
|
+
// Ask user
|
|
170
205
|
console.log("");
|
|
171
206
|
ui.info(`This instance will be launched with a shell command.`);
|
|
172
207
|
const answer = await ui.prompt(`Command name (Enter for ${ui.bold(defaultName)}):`);
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
208
|
+
const aliasName = answer || defaultName;
|
|
209
|
+
|
|
210
|
+
// Remove old alias for this directory
|
|
211
|
+
let lines = profileContent.split("\n");
|
|
212
|
+
lines = lines.filter((l) => !l.includes(egregoreDir));
|
|
213
|
+
// Remove old alias with same name
|
|
214
|
+
const isFish = profileFile.includes("fish");
|
|
215
|
+
const aliasPattern = isFish ? `alias ${aliasName} ` : `alias ${aliasName}=`;
|
|
216
|
+
lines = lines.filter((l) => !l.startsWith(aliasPattern));
|
|
217
|
+
|
|
218
|
+
// Write new alias
|
|
219
|
+
const aliasLine = isFish
|
|
220
|
+
? `alias ${aliasName} '${aliasCmd}'`
|
|
221
|
+
: `alias ${aliasName}='${aliasCmd}'`;
|
|
222
|
+
lines.push("", aliasLine);
|
|
223
|
+
fs.writeFileSync(profile, lines.join("\n"));
|
|
224
|
+
|
|
225
|
+
ui.success(`Added ${ui.dim(aliasName)} to ${profileFile}`);
|
|
226
|
+
return { aliasName, profileFile };
|
|
181
227
|
} catch {
|
|
182
228
|
ui.warn("Could not install shell alias — add it manually.");
|
|
183
229
|
return { aliasName: "egregore", profileFile: ".zshrc" };
|