Skip to content

Commit 4cad6f7

Browse files
add newlines and AnythingLLM CLI comment in shell config
1 parent 21c5411 commit 4cad6f7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/cli/subcommands/setup/handler.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ async function writeToShellConfig(
5050
? await readFile(configPath, "utf-8")
5151
: "";
5252

53-
for (const [key, value] of Object.entries(vars)) {
54-
const pattern = getExportPattern(shell, key);
55-
const exportLine = formatExportLine(shell, key, value);
56-
57-
if (pattern.test(content)) {
58-
content = content.replace(pattern, exportLine);
59-
} else {
60-
if (content.length > 0 && !content.endsWith("\n")) content += "\n";
61-
content += `${exportLine}\n`;
62-
}
53+
// Remove any existing AnythingLLM variable lines and comment header
54+
for (const key of Object.keys(vars)) {
55+
content = content.replace(getExportPattern(shell, key), "");
6356
}
57+
content = content.replace(/^# AnythingLLM CLI$/m, "");
58+
59+
// Clean up excessive blank lines left by removals, then trim end
60+
content = content.replace(/\n{3,}/g, "\n\n").trimEnd();
61+
62+
// Build grouped block with comment header
63+
const exportLines = Object.entries(vars)
64+
.map(([key, value]) => formatExportLine(shell, key, value))
65+
.join("\n");
66+
67+
content += `\n\n# AnythingLLM CLI\n${exportLines}\n`;
6468

6569
await writeFile(configPath, content, "utf-8");
6670
}

0 commit comments

Comments
 (0)