fix: load shell automatically from env for GUI (#948)
This commit is contained in:
@@ -16,7 +16,7 @@ import started from 'electron-squirrel-startup';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { startGoosed } from './goosed';
|
import { startGoosed } from './goosed';
|
||||||
import { getBinaryPath } from './utils/binaryPath';
|
import { getBinaryPath } from './utils/binaryPath';
|
||||||
import { loadZshEnv } from './utils/loadEnv';
|
import { loadShellEnv } from './utils/loadEnv';
|
||||||
import log from './utils/logger';
|
import log from './utils/logger';
|
||||||
import { addRecentDir, loadRecentDirs } from './utils/recentDirs';
|
import { addRecentDir, loadRecentDirs } from './utils/recentDirs';
|
||||||
import {
|
import {
|
||||||
@@ -69,7 +69,7 @@ const parseArgs = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getGooseProvider = () => {
|
const getGooseProvider = () => {
|
||||||
loadZshEnv(app.isPackaged);
|
loadShellEnv(app.isPackaged);
|
||||||
//{env-macro-start}//
|
//{env-macro-start}//
|
||||||
//needed when goose is bundled for a specific provider
|
//needed when goose is bundled for a specific provider
|
||||||
//{env-macro-end}//
|
//{env-macro-end}//
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import path from 'path';
|
|
||||||
import log from './logger';
|
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
|
// Only proceed if running on macOS and in production mode
|
||||||
if (process.platform !== 'darwin' || !isProduction) {
|
if (process.platform !== 'darwin' || !isProduction) {
|
||||||
log.info(
|
log.info(
|
||||||
@@ -15,16 +13,11 @@ export function loadZshEnv(isProduction: boolean = false): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Execute zsh and source the zshrc file, then export all environment variables
|
log.info('LOADING ENV');
|
||||||
const zshrcPath = path.join(process.env.HOME || '', '.zshrc');
|
|
||||||
|
|
||||||
// if no file then return
|
const shell = process.env.SHELL || '/bin/bash'; // Detect user's shell
|
||||||
if (!fs.existsSync(zshrcPath)) {
|
|
||||||
console.log('No zshrc file found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const envStr = execSync(`/bin/zsh -c 'source ${zshrcPath} && env'`, {
|
const envStr = execSync(`${shell} -l -i -c 'env'`, {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,6 +26,7 @@ export function loadZshEnv(isProduction: boolean = false): void {
|
|||||||
const matches = line.match(/^([^=]+)=(.*)$/);
|
const matches = line.match(/^([^=]+)=(.*)$/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
const [, key, value] = matches;
|
const [, key, value] = matches;
|
||||||
|
log.info(`Setting ${key}`);
|
||||||
process.env[key] = value;
|
process.env[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user