-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add fish env loader function and update rules submodule #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,3 +61,5 @@ tags | |
| # Ignore | ||
| result | ||
| ref | ||
| .env | ||
| .env.local | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||||||
| function __hm_load_env_file --description 'Load environment variables from .env' | ||||||||||||||||||||||
| set -l candidate_paths | ||||||||||||||||||||||
| if set -q DOTFILES_ENV_FILE | ||||||||||||||||||||||
| set -a candidate_paths $DOTFILES_ENV_FILE | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| set -a candidate_paths $HOME/dotfiles/.env $HOME/.env | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set -l env_file | ||||||||||||||||||||||
| for candidate in $candidate_paths | ||||||||||||||||||||||
| if test -f $candidate | ||||||||||||||||||||||
| set env_file $candidate | ||||||||||||||||||||||
| break | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if test -z "$env_file" | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| while read -l line | ||||||||||||||||||||||
| set -l trimmed (string trim $line) | ||||||||||||||||||||||
| if test -z "$trimmed" | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| if string match -qr '^#' -- $trimmed | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set trimmed (string replace -r '^export\\s+' '' -- $trimmed) | ||||||||||||||||||||||
| set -l parts (string split -m2 '=' -- $trimmed) | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The option |
||||||||||||||||||||||
| if test (count $parts) -lt 2 | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix regex stripping
Apply this diff: - set trimmed (string replace -r '^export\\s+' '' -- $trimmed)
+ set trimmed (string replace -r '^export\s+' '' -- $trimmed)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set -l key (string trim $parts[1]) | ||||||||||||||||||||||
| set -l value (string trim $parts[2]) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+29
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Useful? React with 👍 / 👎. |
||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
|
Comment on lines
+38
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Additionally, the regex for matching double-quoted strings uses |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set -gx $key $value | ||||||||||||||||||||||
| end < $env_file | ||||||||||||||||||||||
|
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve whitespace in values when exporting. Without quoting, any spaces in the value become separate list elements (e.g., Apply this diff: - set -gx $key $value
+ set -gx -- $key "$value"🤖 Prompt for AI Agents |
||||||||||||||||||||||
| end | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regular expression to remove the
exportprefix is incorrect. The double backslash in\\s+will be treated as a literal backslash followed bys, so it won't match whitespace. To match one or more whitespace characters in a PCRE regex used by fish, you should use\s+.