feat(dotenv): add named pipe (FIFO) support for 1Password Environments#1591
Open
thomaswitt wants to merge 2 commits into
direnv:masterdirenv/direnv:masterfrom
thomaswitt:dotenv-fifo-supportthomaswitt/direnv:dotenv-fifo-supportCopy head branch name to clipboard
Open
feat(dotenv): add named pipe (FIFO) support for 1Password Environments#1591thomaswitt wants to merge 2 commits intodirenv:masterdirenv/direnv:masterfrom thomaswitt:dotenv-fifo-supportthomaswitt/direnv:dotenv-fifo-supportCopy head branch name to clipboard
thomaswitt wants to merge 2 commits into
direnv:masterdirenv/direnv:masterfrom
thomaswitt:dotenv-fifo-supportthomaswitt/direnv:dotenv-fifo-supportCopy head branch name to clipboard
Conversation
A `.env` mounted as a named pipe (FIFO) - e.g. by 1Password Environments to inject secrets without persisting their contents to disk - was rejected by the `[[ -f $path ]]` guard in `dotenv` and `dotenv_if_exists`, since a FIFO is `-p`, not `-f`. Accept `-p` in addition to `-f`, and skip `watch_file` for FIFOs (a FIFO's mtime changes on every read, which would force a reload on every prompt). Regular and not-yet-existing paths are unchanged. Mirrors ohmyzsh/ohmyzsh#13561. Scope: the explicit `dotenv`/`dotenv_if_exists` stdlib functions only; `load_dotenv = true` auto-discovery is intentionally out of scope.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for loading .env from named pipes (FIFOs) while avoiding adding them to DIRENV_WATCHES to prevent reload loops.
Changes:
- Update
dotenv/dotenv_if_existsto skipwatch_filefor FIFOs and treat FIFOs as valid inputs. - Add a regression test covering FIFO behavior and ensuring the watch list does not change.
- Update manpage/docs to describe FIFO support and the “not watched” behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/stdlib.bash | Adds a new test ensuring FIFOs load and do not affect DIRENV_WATCHES. |
| stdlib.sh | Implements FIFO handling by skipping watches for -p paths and allowing FIFOs to be loaded. |
| man/direnv-stdlib.1.md | Documents FIFO support and that named pipes are not watched. |
| man/direnv-stdlib.1 | Updates generated man output to match the markdown documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review feedback: - watch_file now runs only for regular files and not-yet-existing paths (`[[ -f $path || ! -e $path ]]`), so non-FIFO special files such as sockets and devices are no longer watched, matching the comment's stated intent. - Bound the test's background-writer reap so a writer blocked on opening the FIFO can never hang the suite, independent of dotenv's exit path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dotenvanddotenv_if_existsreject a.envthat is a named pipe (FIFO): theguard
[[ -f $path ]]only accepts regular files, so a FIFO (-p) is reported as.env … not foundand nothing is loaded.This matters when a secrets manager mounts the
.envas a FIFO to inject secrets onread without ever writing their contents to disk — e.g. 1Password Environments.
This change accepts named pipes in addition to regular files in both stdlib functions.
Prior art
This mirrors the equivalent change I made to oh-my-zsh's
dotenvplugin, which wasmerged: ohmyzsh/ohmyzsh#13561 ("add named pipe (FIFO) support for 1Password
Environments"). direnv has the same one-line file-type guard — plus a
watch_fileconsideration the shell plugin doesn't have (handled below).
What changed
dotenv()/dotenv_if_exists()accept-p(FIFO) in addition to-f.watch_file: a FIFO's mtime changes on every read, sowatching it would force a reload on every prompt. Regular files and not-yet-existing
paths are still watched — their behavior (including reload-when-created) is unchanged.
direnv dotenv(os.ReadFile) already reads FIFOs to EOF correctly.Scope & notes
dotenv/dotenv_if_existsstdlib calls.load_dotenv = trueauto-discovery uses a different Go path (
fileExists→os.Open+Mode().IsRegular())and is intentionally out of scope.
<dir>/.envfor the guard andwatch_file, but the original argument is still passedto
direnv dotenv. A directory containing a FIFO.envis an exotic case notaddressed here.
Testing
test/stdlib.bashcase covering bothdotenvanddotenv_if_existswith aFIFO: asserts the value loads and that the FIFO is not added to
DIRENV_WATCHES(with a positive control proving
watch_filerecords a regular file in the harness).make buildand the stdlib test suite pass; man page (.1.md+ regenerated roff)updated.