feat: add Fish and Nushell support for environment variables

This commit is contained in:
Memory 2026-02-03 21:16:42 +08:00 committed by GitHub
parent d2f700a0ef
commit dae4939390
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 7 deletions

View File

@ -460,26 +460,42 @@ async function updateTrayMenu(): Promise<void> {
} }
} }
export async function copyEnv(type: 'bash' | 'cmd' | 'powershell'): Promise<void> { export async function copyEnv(
type: 'bash' | 'cmd' | 'powershell' | 'fish' | 'nushell'
): Promise<void> {
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
const { sysProxy } = await getAppConfig() const { sysProxy } = await getAppConfig()
const { host } = sysProxy const { host } = sysProxy
const proxyUrl = `http://${host || '127.0.0.1'}:${mixedPort}`
switch (type) { switch (type) {
case 'bash': { case 'bash': {
clipboard.writeText( 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 break
} }
case 'cmd': { case 'cmd': {
clipboard.writeText( 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 break
} }
case 'powershell': { case 'powershell': {
clipboard.writeText( 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 break
} }

View File

@ -249,7 +249,7 @@ const GeneralConfig: React.FC = () => {
onSelectionChange={async (v) => { onSelectionChange={async (v) => {
try { try {
await patchAppConfig({ await patchAppConfig({
envType: Array.from(v) as ('bash' | 'cmd' | 'powershell')[] envType: Array.from(v) as ('bash' | 'cmd' | 'powershell' | 'fish' | 'nushell')[]
}) })
} catch (e) { } catch (e) {
toast.error(String(e)) toast.error(String(e))
@ -259,6 +259,8 @@ const GeneralConfig: React.FC = () => {
<SelectItem key="bash">Bash</SelectItem> <SelectItem key="bash">Bash</SelectItem>
<SelectItem key="cmd">CMD</SelectItem> <SelectItem key="cmd">CMD</SelectItem>
<SelectItem key="powershell">PowerShell</SelectItem> <SelectItem key="powershell">PowerShell</SelectItem>
<SelectItem key="fish">Fish</SelectItem>
<SelectItem key="nushell">Nushell</SelectItem>
</Select> </Select>
</SettingItem> </SettingItem>
<SettingItem title={t('settings.showFloatingWindow')} divider> <SettingItem title={t('settings.showFloatingWindow')} divider>

View File

@ -100,7 +100,7 @@ interface IpcApi {
setupFirewall: () => Promise<void> setupFirewall: () => Promise<void>
getInterfaces: () => Promise<Record<string, NetworkInterfaceInfo[]>> getInterfaces: () => Promise<Record<string, NetworkInterfaceInfo[]>>
setNativeTheme: (theme: 'system' | 'light' | 'dark') => Promise<void> setNativeTheme: (theme: 'system' | 'light' | 'dark') => Promise<void>
copyEnv: (type: 'bash' | 'cmd' | 'powershell') => Promise<void> copyEnv: (type: 'bash' | 'cmd' | 'powershell' | 'fish' | 'nushell') => Promise<void>
// Update // Update
checkUpdate: () => Promise<IAppVersion | undefined> checkUpdate: () => Promise<IAppVersion | undefined>
downloadAndInstallUpdate: (version: string) => Promise<void> downloadAndInstallUpdate: (version: string) => Promise<void>

View File

@ -235,7 +235,7 @@ interface IAppConfig {
proxyDisplayMode: 'simple' | 'full' proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name' proxyDisplayOrder: 'default' | 'delay' | 'name'
profileDisplayDate?: 'expire' | 'update' profileDisplayDate?: 'expire' | 'update'
envType?: ('bash' | 'cmd' | 'powershell')[] envType?: ('bash' | 'cmd' | 'powershell' | 'fish' | 'nushell')[]
proxyCols: 'auto' | '1' | '2' | '3' | '4' proxyCols: 'auto' | '1' | '2' | '3' | '4'
hideUnavailableProxies?: boolean hideUnavailableProxies?: boolean
connectionDirection: 'asc' | 'desc' connectionDirection: 'asc' | 'desc'