fix: load shell automatically from env for GUI (#948)

This commit is contained in:
Michael Neale
2025-01-31 11:38:28 +11:00
committed by GitHub
parent 3d0c58e5f3
commit 928dc3d1b1
2 changed files with 7 additions and 13 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ import started from 'electron-squirrel-startup';
import path from 'node:path';
import { startGoosed } from './goosed';
import { getBinaryPath } from './utils/binaryPath';
import { loadZshEnv } from './utils/loadEnv';
import { loadShellEnv } from './utils/loadEnv';
import log from './utils/logger';
import { addRecentDir, loadRecentDirs } from './utils/recentDirs';
import {
@@ -69,7 +69,7 @@ const parseArgs = () => {
};
const getGooseProvider = () => {
loadZshEnv(app.isPackaged);
loadShellEnv(app.isPackaged);
//{env-macro-start}//
//needed when goose is bundled for a specific provider
//{env-macro-end}//
+5 -11
View File
@@ -1,9 +1,7 @@
import { execSync } from 'child_process';
import path from 'path';
import log from './logger';
import fs from 'node:fs';
export function loadZshEnv(isProduction: boolean = false): void {
export function loadShellEnv(isProduction: boolean = false): void {
// Only proceed if running on macOS and in production mode
if (process.platform !== 'darwin' || !isProduction) {
log.info(
@@ -15,16 +13,11 @@ export function loadZshEnv(isProduction: boolean = false): void {
}
try {
// Execute zsh and source the zshrc file, then export all environment variables
const zshrcPath = path.join(process.env.HOME || '', '.zshrc');
log.info('LOADING ENV');
// if no file then return
if (!fs.existsSync(zshrcPath)) {
console.log('No zshrc file found');
return;
}
const shell = process.env.SHELL || '/bin/bash'; // Detect user's shell
const envStr = execSync(`/bin/zsh -c 'source ${zshrcPath} && env'`, {
const envStr = execSync(`${shell} -l -i -c 'env'`, {
encoding: 'utf-8',
});
@@ -33,6 +26,7 @@ export function loadZshEnv(isProduction: boolean = false): void {
const matches = line.match(/^([^=]+)=(.*)$/);
if (matches) {
const [, key, value] = matches;
log.info(`Setting ${key}`);
process.env[key] = value;
}
});