Skip to content

fix(tmux): zsh source path + dotenv outer quote stripping#29

Merged
hefgi merged 3 commits into
mainfrom
fix/tmux-env-zsh-source-and-dotenv-quotes
Jun 15, 2026
Merged

fix(tmux): zsh source path + dotenv outer quote stripping#29
hefgi merged 3 commits into
mainfrom
fix/tmux-env-zsh-source-and-dotenv-quotes

Conversation

@hefgi

@hefgi hefgi commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Fixes #27 and #28 — two separate but related bugs in the tmux env-sourcing path that landed in 0.3.0.

#27 — zsh: . '.env' silently fails

After the cd-first fix in #18, the tmux startup command sources env files with the POSIX . builtin and a relative path:

cd '<worktree>'; set -a; . '.env'; set +a; ...

In bash, . '.env' searches the current directory and works. In zsh (default on macOS since Catalina), . does NOT search cwd unless . is in $PATH — it logs .: no such file or directory: .env and continues silently. Per-slot env never loads.

Fix: emit . './.env'. The ./ prefix is POSIX-correct and works in bash, zsh, and dash.

#28 — preamble emits double-quoted values

parse_env_file took everything after = as the literal value. A .env line FOO="bar" round-tripped as export FOO='"bar"' in the per-slug preamble, leaking the literal " characters into the runtime env. Strict consumers like z.literal("development") rejected the quoted string.

Fix: strip a matched outer pair of "..." or '...' from values during parse. Unquoted values, URL/path strings with embedded = or ?, unmatched quotes, and inner escaped quotes are all preserved verbatim. This is the standard dotenv convention.

Why #28 was masked until 0.3.0

The cd-ordering bug from #26 meant the per-slot env never loaded at all — so nobody noticed the preamble itself was malformed. #27 then exposed it on zsh; bash users would have hit it as soon as the preamble started loading.

Tests

  • src/process.rs: 3 tests for build_source_preamble covering the ./ prefix, missing-file skipping, and empty-tree behavior. Includes a negative assertion that pins the regression — the bare . '.env' form must never be re-emitted.
  • src/env.rs: 7 tests for parse_env_file covering double, single, unquoted, unmatched, inner-escaped, empty-quoted, and bare-quote-char values.

cargo fmt --check, cargo clippy -- -D warnings, cargo test --bin ecluse (439 unit tests passing) all green. The docker_e2e integration suite is unrelated to these changes (it needs a pre-pulled test image and skips elsewhere).

Test plan

  • On zsh: tmux capture-pane -t ecluse-<slug>:<service> -p -S -100 shows no no such file or directory: .env lines
  • In a tmux window, echo "$ECLUSE_<NAME>_PORT" resolves to the slot's port even after ecluse up <other-slug> ran in another terminal
  • A .env line ONYX_ENVIRONMENT="development" results in a runtime env where [ "$ONYX_ENVIRONMENT" = development ] is true (no quotes)
  • A .env line DATABASE_URL=postgres://x:5433/db?a=b round-trips unchanged

hefgi added 3 commits June 15, 2026 09:20
zsh's POSIX `.` builtin does not search the current directory unless
`.` is in `$PATH` — the default macOS shell is zsh, so the bare
`. '.env'` form silently failed there with "no such file or directory"
even after the cd-first fix from #18. Services in tmux windows ended
up without the per-slot env: `ECLUSE_*` vars from the per-slug preamble
were fine, but anything from `.env`, `.env.local`, or `.env.ecluse`
that wasn't duplicated into the preamble was lost.

build_source_preamble now emits `. './.env'` (and the same for
`.env.local`/`.env.ecluse`). The `./` prefix is POSIX-correct and works
in bash, zsh, and dash. Adds three regression tests covering the
correct prefix, the missing-files-skip behavior, and the empty-tree
case.

Fixes #27
parse_env_file treated everything after `=` as the literal value,
which round-tripped `FOO="bar"` as the 5-character value `"bar"`
(quotes included) when the value got re-emitted in the per-slug
tmux preamble as `export FOO='"bar"'`. Downstream consumers that
check against a literal string (e.g. `z.literal("development")`)
would reject the quoted value, breaking any framework using
conventional dotenv `KEY="value"` style.

A matched outer pair of `"..."` or `'...'` is now stripped — the
standard dotenv convention where `FOO=bar` and `FOO="bar"` mean the
same thing. Unmatched quotes (`FOO="oops`), inner escaped quotes
(`MSG="hello \"world\""`), and unquoted values containing literal
quote chars or `=` (`URL=postgres://x:5433/db?a=b`) are preserved
verbatim, so URLs and query strings round-trip unchanged.

Adds seven regression tests covering double, single, unquoted,
unmatched, inner-escaped, empty-quoted, and bare-quote-char cases.

Fixes #28
@hefgi hefgi merged commit 9294c51 into main Jun 15, 2026
2 checks passed
@hefgi hefgi deleted the fix/tmux-env-zsh-source-and-dotenv-quotes branch June 15, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zsh: tmux startup '. <file>' fails — POSIX dot builtin doesn't search cwd in zsh, need './<file>' or 'source'

1 participant