Scripts work under pwsh on Linux and macOS
Home, VS Code user folder and CLI are resolved per platform (with VSCODE_USER_DIR as an override); dev-link makes a symlink where a junction is not available. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169iPWwKHZoBTNN9qwXiwqk
This commit is contained in:
+49
-6
@@ -71,7 +71,7 @@ function Get-GiteaToken {
|
||||
if ($Token) { return $Token }
|
||||
if ($env:GITEA_TOKEN) { return $env:GITEA_TOKEN }
|
||||
|
||||
$file = Join-Path $env:USERPROFILE '.gitea-token'
|
||||
$file = Join-Path (Get-HomeDir) '.gitea-token'
|
||||
if (Test-Path $file) {
|
||||
$value = (Get-Content $file -Raw).Trim()
|
||||
if ($value) { return $value }
|
||||
@@ -283,16 +283,59 @@ function Get-VsceCommand {
|
||||
$entry
|
||||
}
|
||||
|
||||
function Test-IsWindows {
|
||||
<#
|
||||
Windows PowerShell 5.1 has no $IsWindows (it only ever runs on Windows); pwsh 6+
|
||||
defines it on every platform. So: undefined means Windows.
|
||||
#>
|
||||
if (Test-Path variable:IsWindows) { return [bool] $IsWindows }
|
||||
return $true
|
||||
}
|
||||
|
||||
function Get-HomeDir {
|
||||
<# $HOME is set by both editions on every platform; USERPROFILE only exists on Windows. #>
|
||||
if ($HOME) { return $HOME }
|
||||
if ($env:USERPROFILE) { return $env:USERPROFILE }
|
||||
throw 'Neither $HOME nor USERPROFILE is set.'
|
||||
}
|
||||
|
||||
function Get-CodeUserDir {
|
||||
<#
|
||||
VS Code's user folder, where settings.json and keybindings.json live. Set
|
||||
VSCODE_USER_DIR to override, e.g. for Insiders or a portable install.
|
||||
#>
|
||||
if ($env:VSCODE_USER_DIR) { return $env:VSCODE_USER_DIR }
|
||||
if (Test-IsWindows) { return Join-Path $env:APPDATA 'Code\User' }
|
||||
if ((Test-Path variable:IsMacOS) -and $IsMacOS) {
|
||||
return Join-Path (Get-HomeDir) 'Library/Application Support/Code/User'
|
||||
}
|
||||
$configHome = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { Join-Path (Get-HomeDir) '.config' }
|
||||
return Join-Path $configHome 'Code/User'
|
||||
}
|
||||
|
||||
function Get-CodeCommand {
|
||||
<# The VS Code CLI. Not always on PATH, so fall back to the usual install locations. #>
|
||||
$onPath = Get-Command code -ErrorAction SilentlyContinue
|
||||
if ($onPath) { return $onPath.Source }
|
||||
|
||||
$candidates = @(
|
||||
(Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code\bin\code.cmd'),
|
||||
'C:\Program Files\Microsoft VS Code\bin\code.cmd',
|
||||
(Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd')
|
||||
)
|
||||
$candidates = if (Test-IsWindows) {
|
||||
@(
|
||||
(Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code\bin\code.cmd'),
|
||||
'C:\Program Files\Microsoft VS Code\bin\code.cmd',
|
||||
(Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd')
|
||||
)
|
||||
} else {
|
||||
@(
|
||||
'/usr/bin/code',
|
||||
'/usr/share/code/bin/code',
|
||||
'/snap/bin/code',
|
||||
'/var/lib/flatpak/exports/bin/com.visualstudio.code',
|
||||
(Join-Path (Get-HomeDir) '.local/bin/code'),
|
||||
'/usr/local/bin/code',
|
||||
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
|
||||
'/usr/bin/code-insiders'
|
||||
)
|
||||
}
|
||||
foreach ($candidate in $candidates) {
|
||||
if (Test-Path $candidate) { return $candidate }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user