From dae4939390e2e33159b576156e5ee4ef99ebccc2 Mon Sep 17 00:00:00 2001 From: Memory <134070804+Memory2314@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:16:42 +0800 Subject: [PATCH] feat: add Fish and Nushell support for environment variables --- src/main/resolve/tray.ts | 24 +++++++++++++++---- .../components/settings/general-config.tsx | 4 +++- src/renderer/src/utils/ipc.ts | 2 +- src/shared/types.d.ts | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/resolve/tray.ts b/src/main/resolve/tray.ts index bf719d0..dddf9a1 100644 --- a/src/main/resolve/tray.ts +++ b/src/main/resolve/tray.ts @@ -460,26 +460,42 @@ async function updateTrayMenu(): Promise { } } -export async function copyEnv(type: 'bash' | 'cmd' | 'powershell'): Promise { +export async function copyEnv( + type: 'bash' | 'cmd' | 'powershell' | 'fish' | 'nushell' +): Promise { const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() const { sysProxy } = await getAppConfig() const { host } = sysProxy + const proxyUrl = `http://${host || '127.0.0.1'}:${mixedPort}` + switch (type) { case 'bash': { clipboard.writeText( - `export https_proxy=http://${host || '127.0.0.1'}:${mixedPort} http_proxy=http://${host || '127.0.0.1'}:${mixedPort} all_proxy=http://${host || '127.0.0.1'}:${mixedPort}` + `export https_proxy=${proxyUrl} http_proxy=${proxyUrl} all_proxy=${proxyUrl}` ) break } case 'cmd': { clipboard.writeText( - `set http_proxy=http://${host || '127.0.0.1'}:${mixedPort}\r\nset https_proxy=http://${host || '127.0.0.1'}:${mixedPort}` + `set http_proxy=${proxyUrl}\r\nset https_proxy=${proxyUrl}` ) break } case 'powershell': { clipboard.writeText( - `$env:HTTP_PROXY="http://${host || '127.0.0.1'}:${mixedPort}"; $env:HTTPS_PROXY="http://${host || '127.0.0.1'}:${mixedPort}"` + `$env:HTTP_PROXY="${proxyUrl}"; $env:HTTPS_PROXY="${proxyUrl}"` + ) + break + } + case 'fish': { + clipboard.writeText( + `set -x http_proxy ${proxyUrl}; set -x https_proxy ${proxyUrl}; set -x all_proxy ${proxyUrl}` + ) + break + } + case 'nushell': { + clipboard.writeText( + `$env.HTTP_PROXY = "${proxyUrl}"; $env.HTTPS_PROXY = "${proxyUrl}"; $env.ALL_PROXY = "${proxyUrl}"` ) break } diff --git a/src/renderer/src/components/settings/general-config.tsx b/src/renderer/src/components/settings/general-config.tsx index a0c8ab9..e6b18b8 100644 --- a/src/renderer/src/components/settings/general-config.tsx +++ b/src/renderer/src/components/settings/general-config.tsx @@ -249,7 +249,7 @@ const GeneralConfig: React.FC = () => { onSelectionChange={async (v) => { try { await patchAppConfig({ - envType: Array.from(v) as ('bash' | 'cmd' | 'powershell')[] + envType: Array.from(v) as ('bash' | 'cmd' | 'powershell' | 'fish' | 'nushell')[] }) } catch (e) { toast.error(String(e)) @@ -259,6 +259,8 @@ const GeneralConfig: React.FC = () => { Bash CMD PowerShell + Fish + Nushell diff --git a/src/renderer/src/utils/ipc.ts b/src/renderer/src/utils/ipc.ts index 9beb749..a4a6956 100644 --- a/src/renderer/src/utils/ipc.ts +++ b/src/renderer/src/utils/ipc.ts @@ -100,7 +100,7 @@ interface IpcApi { setupFirewall: () => Promise getInterfaces: () => Promise> setNativeTheme: (theme: 'system' | 'light' | 'dark') => Promise - copyEnv: (type: 'bash' | 'cmd' | 'powershell') => Promise + copyEnv: (type: 'bash' | 'cmd' | 'powershell' | 'fish' | 'nushell') => Promise // Update checkUpdate: () => Promise downloadAndInstallUpdate: (version: string) => Promise diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index ec9b69a..e1023cb 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -235,7 +235,7 @@ interface IAppConfig { proxyDisplayMode: 'simple' | 'full' proxyDisplayOrder: 'default' | 'delay' | 'name' profileDisplayDate?: 'expire' | 'update' - envType?: ('bash' | 'cmd' | 'powershell')[] + envType?: ('bash' | 'cmd' | 'powershell' | 'fish' | 'nushell')[] proxyCols: 'auto' | '1' | '2' | '3' | '4' hideUnavailableProxies?: boolean connectionDirection: 'asc' | 'desc'