mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
fix: load shell environment variables on app startup (#7223)
Add shell-env integration to fetch environment variables from the user's shell config files (.zshrc, .zshenv, etc.) so that proxy settings and other exports are available in process.env for both Electron and CLI.
This commit is contained in:
33
packages/bruno-requests/src/utils/shell-env.ts
Normal file
33
packages/bruno-requests/src/utils/shell-env.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Shell Environment Utility
|
||||
*
|
||||
* Fetches environment variables from the user's shell configuration files (e.g., .zshenv, .bashrc)
|
||||
*/
|
||||
|
||||
const fetchShellEnv = async (): Promise<Record<string, string>> => {
|
||||
// Windows handles environment variables differently - skip
|
||||
if (process.platform === 'win32') {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
// shell-env is ESM-only, so we use dynamic import
|
||||
const { shellEnv } = await import('shell-env');
|
||||
const env = await shellEnv();
|
||||
return env;
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes process.env with shell environment variables.
|
||||
* Should be called early in the app startup.
|
||||
*
|
||||
* @returns The fetched shell environment variables
|
||||
*/
|
||||
export const initializeShellEnv = async (): Promise<Record<string, string>> => {
|
||||
const shellEnvVars = await fetchShellEnv();
|
||||
Object.assign(process.env, shellEnvVars);
|
||||
return shellEnvVars;
|
||||
};
|
||||
Reference in New Issue
Block a user