File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,13 +149,20 @@ function Initialize-Environment {
149149
150150 # 自动检测代理(缓存 5 分钟避免每次 profile 加载都做 TCP 探测)
151151 if (-not $SkipProxy ) {
152- $proxyState = Invoke-WithCache - Key " proxy-auto-detect" - MaxAge ([TimeSpan ]::FromMinutes(5 )) - CacheType Text - ScriptBlock {
153- Set-Proxy - Command auto
154- $result = if ($env: http_proxy ) { ' on' } else { ' off' }
155- return $result
152+ try {
153+ $proxyState = Invoke-WithCache - Key " proxy-auto-detect" - MaxAge ([TimeSpan ]::FromMinutes(5 )) - CacheType Text - ScriptBlock {
154+ Set-Proxy - Command auto
155+ $result = if ($env: http_proxy ) { ' on' } else { ' off' }
156+ return $result
157+ }
158+ if ($proxyState -eq ' on' -and -not $env: http_proxy ) {
159+ Set-Proxy - Command on
160+ }
156161 }
157- if ($proxyState -eq ' on' -and -not $env: http_proxy ) {
158- Set-Proxy - Command on
162+ catch {
163+ Write-Verbose " 代理自动检测失败: $ ( $_.Exception.Message ) "
164+ # 回退到不缓存的直接探测
165+ Set-Proxy - Command auto
159166 }
160167 }
161168
@@ -184,7 +191,9 @@ function Initialize-Environment {
184191 $foundCommands = Get-Command - Name $toolNames - CommandType Application - ErrorAction SilentlyContinue
185192 if ($foundCommands ) {
186193 foreach ($cmd in $foundCommands ) {
187- $availableTools.Add ($cmd.Name ) | Out-Null
194+ # Windows 上 .Name 带扩展名 (如 starship.exe),统一去掉扩展名
195+ $toolName = [System.IO.Path ]::GetFileNameWithoutExtension($cmd.Name )
196+ $availableTools.Add ($toolName ) | Out-Null
188197 }
189198 }
190199
You can’t perform that action at this time.
0 commit comments