Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(install): emit fish-native PATH syntax for fish configs (#319)

Martin Vogel30dfa952d95f
diff --git a/src/cli/cli.c b/src/cli/cli.c
index a384504ae..6ef7a0114 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -1905,8 +1905,19 @@ int cbm_ensure_path(const char *bin_dir, const char *rc_file, bool dry_run) {
return CLI_ERR;
}
+ /* fish uses a different syntax than POSIX shells: `export PATH="...:$PATH"`
+ * is a syntax error in fish and breaks config.fish (#319). When the target
+ * is a fish config, emit the fish-native `fish_add_path` (idempotent,
+ * prepends only if absent) instead. */
+ size_t rc_len = strlen(rc_file);
+ bool is_fish = rc_len >= CBM_SZ_5 && strcmp(rc_file + rc_len - CBM_SZ_5, ".fish") == 0;
+
char line[CLI_BUF_1K];
- snprintf(line, sizeof(line), "export PATH=\"%s:$PATH\"", bin_dir);
+ if (is_fish) {
+ snprintf(line, sizeof(line), "fish_add_path %s", bin_dir);
+ } else {
+ snprintf(line, sizeof(line), "export PATH=\"%s:$PATH\"", bin_dir);
+ }
/* Check if already present in rc file */
FILE *f = fopen(rc_file, "r");
diff --git a/tests/test_cli.c b/tests/test_cli.c
index 25c2c4e6d..f7b695900 100644
--- a/tests/test_cli.c
+++ b/tests/test_cli.c
@@ -952,6 +952,35 @@ TEST(cli_ensure_path_dry_run) {
PASS();
}
+/* issue #319: a fish config must get fish-native syntax, never `export PATH=`
+ * (which is a syntax error in fish and breaks config.fish). */
+TEST(cli_ensure_path_fish_syntax_issue319) {
+ char tmpdir[256];
+ snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-path-XXXXXX");
+ if (!cbm_mkdtemp(tmpdir))
+ SKIP("cbm_mkdtemp failed");
+
+ char rcfile[512];
+ snprintf(rcfile, sizeof(rcfile), "%s/config.fish", tmpdir);
+ write_test_file(rcfile, "# existing fish config\n");
+
+ int rc = cbm_ensure_path("/usr/local/bin", rcfile, false);
+ ASSERT_EQ(rc, 0);
+
+ const char *data = read_test_file(rcfile);
+ ASSERT_NOT_NULL(data);
+ /* fish-native form, and NO sh-style export. */
+ ASSERT(strstr(data, "fish_add_path /usr/local/bin") != NULL);
+ ASSERT(strstr(data, "export PATH") == NULL);
+
+ /* Idempotent: a second call detects the existing fish line. */
+ int rc2 = cbm_ensure_path("/usr/local/bin", rcfile, false);
+ ASSERT_EQ(rc2, 1);
+
+ test_rmdir_r(tmpdir);
+ PASS();
+}
+
/* ═══════════════════════════════════════════════════════════════════
* File copy tests (port of update_test.go)
* ═══════════════════════════════════════════════════════════════════ */
@@ -2506,6 +2535,7 @@ SUITE(cli) {
RUN_TEST(cli_ensure_path_append);
RUN_TEST(cli_ensure_path_already_present);
RUN_TEST(cli_ensure_path_dry_run);
+ RUN_TEST(cli_ensure_path_fish_syntax_issue319);
/* File copy (2 tests — update_test.go) */
RUN_TEST(cli_copy_file);