Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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#1591
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

@thomaswitt

Copy link
Copy Markdown

Summary

dotenv and dotenv_if_exists reject a .env that is a named pipe (FIFO): the
guard [[ -f $path ]] only accepts regular files, so a FIFO (-p) is reported as
.env … not found and nothing is loaded.

This matters when a secrets manager mounts the .env as a FIFO to inject secrets on
read 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 dotenv plugin, which was
merged: ohmyzsh/ohmyzsh#13561 ("add named pipe (FIFO) support for 1Password
Environments"). direnv has the same one-line file-type guard — plus a watch_file
consideration the shell plugin doesn't have (handled below).

What changed

  • dotenv() / dotenv_if_exists() accept -p (FIFO) in addition to -f.
  • A FIFO is not passed to watch_file: a FIFO's mtime changes on every read, so
    watching 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.
  • No Go change: direnv dotenv (os.ReadFile) already reads FIFOs to EOF correctly.

Scope & notes

  • Scoped to the explicit dotenv / dotenv_if_exists stdlib calls. load_dotenv = true
    auto-discovery uses a different Go path (fileExistsos.Open + Mode().IsRegular())
    and is intentionally out of scope.
  • The FIFO producer must write the env and then close (EOF), since the read drains to EOF.
  • Pre-existing / unchanged: when the argument is a directory it is normalized to
    <dir>/.env for the guard and watch_file, but the original argument is still passed
    to direnv dotenv. A directory containing a FIFO .env is an exotic case not
    addressed here.

Testing

  • New test/stdlib.bash case covering both dotenv and dotenv_if_exists with a
    FIFO: asserts the value loads and that the FIFO is not added to DIRENV_WATCHES
    (with a positive control proving watch_file records a regular file in the harness).
  • make build and the stdlib test suite pass; man page (.1.md + regenerated roff)
    updated.

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.
Copilot AI review requested due to automatic review settings June 16, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_exists to skip watch_file for 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.

Comment thread test/stdlib.bash Outdated
Comment thread test/stdlib.bash
Comment thread test/stdlib.bash
Comment thread stdlib.sh
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.