Skip to content

chore: add fish env loader function and update rules submodule - #247

Merged
shunkakinoki merged 1 commit into
mainfrom
chore/update-fish-env-and-rules
Sep 30, 2025
Merged

chore: add fish env loader function and update rules submodule#247
shunkakinoki merged 1 commit into
mainfrom
chore/update-fish-env-and-rules

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Sep 30, 2025

Copy link
Copy Markdown
Owner

Summary

  • Add fish function to automatically load environment variables from .env files for better shell integration
  • Update rules submodule to incorporate latest configuration changes

Summary by CodeRabbit

  • New Features

    • Fish shell now auto-loads environment variables from a .env file at startup. Supports standard .env formatting (comments, quoted values) and searches common locations, exporting variables for the session.
  • Chores

    • Added .env and .env.local to .gitignore to prevent accidental commits.
    • Updated rules submodule to the latest reference.

- Introduce __hm_load_env_file.fish for Home Manager env loading
- Modify fish/default.nix and .gitignore accordingly
- Refresh rules submodule to latest commit bf5e1f9
@coderabbitai

coderabbitai Bot commented Sep 30, 2025

Copy link
Copy Markdown

Walkthrough

Adds .env files to .gitignore. Introduces a Fish function (__hm_load_env_file) to load environment variables from .env files and invokes it during Fish interactive shell initialization. Updates a submodule pointer in rules.

Changes

Cohort / File(s) Summary
Git ignore updates
\.gitignore
Add .env and .env.local to ignored files.
Fish shell init
home-manager/programs/fish/default.nix
Replace greeting-disabling line with a call to __hm_load_env_file before setting greeting; alters init sequence to load env vars first.
Fish env loader function
home-manager/programs/fish/functions/__hm_load_env_file.fish
New function to load environment variables from a .env file: selects candidate paths, parses lines (supports comments, export, quotes), and exports key-value pairs globally.
Submodule update
rules
Advance submodule reference from b140aa5... to bf5e1f9....

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant Fish as Fish (interactive)
    participant Loader as __hm_load_env_file
    participant FS as Filesystem

    User->>Fish: Start interactive shell
    Fish->>Loader: Call to load env
    activate Loader
    Loader->>FS: Check DOTFILES_ENV_FILE<br/>else probe $HOME/dotfiles/.env, $HOME/.env
    FS-->>Loader: Return first existing file or none
    alt Env file found
        Loader->>FS: Read file line-by-line
        loop For each parsed KEY=VALUE
            Loader->>Fish: set -gx KEY VALUE
        end
    else No env file
        Note over Loader: No-op
    end
    deactivate Loader
    Fish->>Fish: Continue init (e.g., greeting settings)
    Fish-->>User: Ready prompt
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nuzzle the .env, a secret clover leaf,
Hop-load the keys, quick paws, no grief.
Shell wakes warm with variables anew,
Submodule nudged—a tidy little to-do.
With a whisk and a wink, I’m ready to run—
Fish says hello; I’m off for fun! 🐇🌱

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title concisely and accurately highlights the two main changes introduced by the branch: the addition of a Fish environment loader function and the update to the rules submodule. It directly corresponds to the files modified and the objectives outlined without extraneous details or vague language. The title is specific, clear, and follows a conventional commit style, making it easy for teammates to understand the purpose of the changes at a glance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/update-fish-env-and-rules

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the development environment's setup by automating the loading of environment variables from .env files directly into the Fish shell. This streamlines the process of managing application configurations and ensures that necessary variables are always available. Concurrently, the rules submodule has been brought up to date, ensuring that the latest configurations and guidelines are consistently applied across the project.

Highlights

  • Fish Shell Environment Loading: A new Fish shell function, __hm_load_env_file, has been introduced to automatically parse and load environment variables from .env files, enhancing shell integration and configuration management.
  • Rules Submodule Update: The rules git submodule has been updated to its latest commit, bf5e1f9d9a505a57b15f80945d105e992b77a9f6, incorporating recent configuration changes.
  • Gitignore Configuration: The .gitignore file has been updated to include .env and .env.local, preventing these files, which often contain sensitive information, from being accidentally committed to the repository.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@shunkakinoki
shunkakinoki enabled auto-merge (squash) September 30, 2025 04:53

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +29 to +37
set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
set -l parts (string split -m2 '=' -- $trimmed)
if test (count $parts) -lt 2
continue
end

set -l key (string trim $parts[1])
set -l value (string trim $parts[2])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Strip export prefix before parsing keys

The regex used to drop an optional export prefix is '^export\\s+', which matches a literal \s string instead of whitespace because the backslash is escaped twice. Lines like export FOO=bar therefore leave trimmed as export FOO=bar, and the subsequent set -gx assigns a variable named export with values FOO and bar rather than exporting FOO. .env files that include the export keyword will silently fail to load the intended variables. Use '^export\s+' or '^export\s+' with a single backslash so the whitespace is removed before splitting.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0603cdf and 6977052.

📒 Files selected for processing (4)
  • .gitignore (1 hunks)
  • home-manager/programs/fish/default.nix (1 hunks)
  • home-manager/programs/fish/functions/__hm_load_env_file.fish (1 hunks)
  • rules (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
home-manager/**

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Keep home-manager configurations under home-manager/

Files:

  • home-manager/programs/fish/functions/__hm_load_env_file.fish
  • home-manager/programs/fish/default.nix
**/*.nix

📄 CodeRabbit inference engine (CLAUDE.md)

Format all Nix files with nixfmt

**/*.nix: Nix: Use 2 spaces for indentation
Nix: Keep line length under 100 characters
Nix: Sort attribute sets alphabetically
Nix: Use consistent spacing around operators
Nix: Format lists and sets consistently

Follow the Nix expression language style guide

Files:

  • home-manager/programs/fish/default.nix
**/default.nix

📄 CodeRabbit inference engine (CLAUDE.md)

Use default.nix files for module exports

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/*/default.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

home-manager/programs/*/default.nix: Program configurations must be located in home-manager/programs// with configuration in default.nix
Program configurations should prefer Home Manager’s built-in modules when available
Program configurations should include all necessary dependencies
Program configurations should follow the provided template (programs..enable, package, and settings attrset)

Files:

  • home-manager/programs/fish/default.nix
home-manager/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Use proper indentation and formatting in Nix files

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/**/default.nix

📄 CodeRabbit inference engine (.cursor/rules/nix.mdc)

Program configurations in home-manager/programs should be organized by program name (one directory per program with a default.nix)

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/nix.mdc)

home-manager/programs/**/*.nix: Program configurations should include all necessary dependencies
Use home.packages for package installations in program configurations
Use programs. options provided by Home Manager when available

Files:

  • home-manager/programs/fish/default.nix
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: nix-linux
  • GitHub Check: nix-nixos
  • GitHub Check: nix-darwin
  • GitHub Check: docker-build-push (linux/amd64, -amd64, amd64)
  • GitHub Check: e2e-run (NixOS, ubuntu-latest)
  • GitHub Check: e2e-run (MacOS, macos-latest)
  • GitHub Check: e2e-run (Ubuntu, ubuntu-latest)
🔇 Additional comments (1)
home-manager/programs/fish/default.nix (1)

16-16: Env loader hook looks good.

Bringing __hm_load_env_file into interactiveShellInit ensures Fish sessions hydrate the environment before other setup runs. Nice touch.

Comment on lines +29 to +33
set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
set -l parts (string split -m2 '=' -- $trimmed)
if test (count $parts) -lt 2
continue
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix regex stripping export.

^export\\s+ matches the literal string export\s instead of whitespace, so .env lines that start with export keep the prefix and later try to set a variable named export. Fixing the regex to ^export\s+ correctly removes the prefix.

Apply this diff:

-    set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
+    set trimmed (string replace -r '^export\s+' '' -- $trimmed)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
set -l parts (string split -m2 '=' -- $trimmed)
if test (count $parts) -lt 2
continue
end
set trimmed (string replace -r '^export\s+' '' -- $trimmed)
set -l parts (string split -m2 '=' -- $trimmed)
if test (count $parts) -lt 2
continue
end
🤖 Prompt for AI Agents
home-manager/programs/fish/functions/__hm_load_env_file.fish around lines 29-33:
the regex used in string replace is escaping the backslash so it matches a
literal "\s" rather than whitespace; change the regex from '^export\\s+' to
'^export\s+' so the pattern correctly strips the "export" prefix followed by any
whitespace from the start of the line.

Comment on lines +44 to +45
set -gx $key $value
end < $env_file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Preserve whitespace in values when exporting.

Without quoting, any spaces in the value become separate list elements (e.g., FOO="hello world" becomes two words). Quoting the value and stopping option parsing keeps the original string intact.

Apply this diff:

-    set -gx $key $value
+    set -gx -- $key "$value"
🤖 Prompt for AI Agents
In home-manager/programs/fish/functions/__hm_load_env_file.fish around lines
44-45, the export uses set -gx $key $value which can split values containing
spaces; change it to use a stop-opts marker and quoted value: set -gx -- $key
"$value" so option parsing is disabled and the original string (including
whitespace) is preserved when exporting.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new fish function to load environment variables from .env files, which is a great addition for shell integration. I've reviewed the implementation and found a few critical and high-severity issues in the parsing logic that would cause the script to fail or behave incorrectly. My review includes suggestions to fix these issues to ensure the function is robust and works as expected.

end

set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
set -l parts (string split -m2 '=' -- $trimmed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The option -m2 for string split is invalid syntax in fish shell and will cause the script to fail. To split the line only on the first occurrence of =, you should use the option -m 1. This will correctly separate the key from the value, which is crucial for parsing lines where the value itself might contain an equals sign (e.g., DATABASE_URL=postgres://...).

    set -l parts (string split -m 1 '=' -- $trimmed)

continue
end

set trimmed (string replace -r '^export\\s+' '' -- $trimmed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The regular expression to remove the export prefix is incorrect. The double backslash in \\s+ will be treated as a literal backslash followed by s, so it won't match whitespace. To match one or more whitespace characters in a PCRE regex used by fish, you should use \s+.

    set trimmed (string replace -r '^export\s+' '' -- $trimmed)

Comment on lines +38 to +42
if string match -qr "^'.*'\z" -- $value
set value (string trim --chars "'" -- $value)
else if string match -qr '^".*"$' -- $value
set value (string trim --chars '"' -- $value)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using string trim --chars to remove quotes can be unreliable. For example, a value like ''foo'' would be incorrectly trimmed to foo instead of the intended 'foo'. A more robust approach is to use string sub --start=2 --end=-2, which removes only the first and last characters.

Additionally, the regex for matching double-quoted strings uses $ to match the end of the line. It's better practice to use \z to match the end of the string, which is more accurate if values span multiple lines.

    if string match -qr "^'.*'\z" -- $value
      set value (string sub --start=2 --end=-2 -- $value)
    else if string match -qr '^\".*\"\z' -- $value
      set value (string sub --start=2 --end=-2 -- $value)
    end

@shunkakinoki
shunkakinoki merged commit abaf29c into main Sep 30, 2025
22 checks passed
@shunkakinoki
shunkakinoki deleted the chore/update-fish-env-and-rules branch September 30, 2025 05:20
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.

1 participant