pwsh: Use fully qualified names when invoking cmdlets (#1236)

This commit is contained in:
Ajeet D'Souza 2026-05-12 05:12:30 +05:30 committed by GitHub
parent 1683e7b8ed
commit b151e6da3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 12 deletions

View File

@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- PowerShell: use fully qualified names when invoking cmdlets.
- Bash/Fish/POSIX/Zsh: resolve symlinks on Windows. - Bash/Fish/POSIX/Zsh: resolve symlinks on Windows.
## [0.9.9] - 2026-01-31 ## [0.9.9] - 2026-01-31

View File

@ -19,7 +19,7 @@ function global:__zoxide_bin {
# pwd based on zoxide's format. # pwd based on zoxide's format.
function global:__zoxide_pwd { function global:__zoxide_pwd {
$cwd = Get-Location $cwd = Microsoft.PowerShell.Management\Get-Location
if ($cwd.Provider.Name -eq "FileSystem") { if ($cwd.Provider.Name -eq "FileSystem") {
$cwd.ProviderPath $cwd.ProviderPath
} }
@ -29,23 +29,23 @@ function global:__zoxide_pwd {
function global:__zoxide_cd($dir, $literal) { function global:__zoxide_cd($dir, $literal) {
$dir = if ($literal) { $dir = if ($literal) {
if ($null -eq $dir) { if ($null -eq $dir) {
Set-Location Microsoft.PowerShell.Management\Set-Location
} else { } else {
Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop Microsoft.PowerShell.Management\Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop
} }
} else { } else {
if ($dir -eq '-' -and ($PSVersionTable.PSVersion -lt 6.1)) { if ($dir -eq '-' -and ($PSVersionTable.PSVersion -lt 6.1)) {
Write-Error "cd - is not supported below PowerShell 6.1. Please upgrade your version of PowerShell." Microsoft.PowerShell.Utility\Write-Error "cd - is not supported below PowerShell 6.1. Please upgrade your version of PowerShell."
} }
elseif ($dir -eq '+' -and ($PSVersionTable.PSVersion -lt 6.2)) { elseif ($dir -eq '+' -and ($PSVersionTable.PSVersion -lt 6.2)) {
Write-Error "cd + is not supported below PowerShell 6.2. Please upgrade your version of PowerShell." Microsoft.PowerShell.Utility\Write-Error "cd + is not supported below PowerShell 6.2. Please upgrade your version of PowerShell."
} }
else { else {
Set-Location -Path $dir -Passthru -ErrorAction Stop Microsoft.PowerShell.Management\Set-Location -Path $dir -Passthru -ErrorAction Stop
} }
} }
{%- if echo %} {%- if echo %}
Write-Output $dir.Path Microsoft.PowerShell.Utility\Write-Output $dir.Path
{%- endif %} {%- endif %}
} }
@ -84,7 +84,7 @@ function global:__zoxide_hook {
{%- endif %} {%- endif %}
# Initialize hook. # Initialize hook.
$global:__zoxide_hooked = (Get-Variable __zoxide_hooked -ErrorAction Ignore -ValueOnly) $global:__zoxide_hooked = (Microsoft.PowerShell.Utility\Get-Variable __zoxide_hooked -ErrorAction Ignore -ValueOnly)
if ($global:__zoxide_hooked -ne 1) { if ($global:__zoxide_hooked -ne 1) {
$global:__zoxide_hooked = 1 $global:__zoxide_hooked = 1
$global:__zoxide_prompt_old = $function:prompt $global:__zoxide_prompt_old = $function:prompt
@ -110,10 +110,10 @@ function global:__zoxide_z {
elseif ($args.Length -eq 1 -and ($args[0] -eq '-' -or $args[0] -eq '+')) { elseif ($args.Length -eq 1 -and ($args[0] -eq '-' -or $args[0] -eq '+')) {
__zoxide_cd $args[0] $false __zoxide_cd $args[0] $false
} }
elseif ($args.Length -eq 1 -and (Test-Path -PathType Container -LiteralPath $args[0])) { elseif ($args.Length -eq 1 -and (Microsoft.PowerShell.Management\Test-Path -PathType Container -LiteralPath $args[0])) {
__zoxide_cd $args[0] $true __zoxide_cd $args[0] $true
} }
elseif ($args.Length -eq 1 -and (Test-Path -PathType Container -Path $args[0] )) { elseif ($args.Length -eq 1 -and (Microsoft.PowerShell.Management\Test-Path -PathType Container -Path $args[0] )) {
__zoxide_cd $args[0] $false __zoxide_cd $args[0] $false
} }
else { else {
@ -145,8 +145,8 @@ function global:__zoxide_zi {
{%- match cmd %} {%- match cmd %}
{%- when Some with (cmd) %} {%- when Some with (cmd) %}
Set-Alias -Name {{cmd}} -Value __zoxide_z -Option AllScope -Scope Global -Force Microsoft.PowerShell.Utility\Set-Alias -Name {{cmd}} -Value __zoxide_z -Option AllScope -Scope Global -Force
Set-Alias -Name {{cmd}}i -Value __zoxide_zi -Option AllScope -Scope Global -Force Microsoft.PowerShell.Utility\Set-Alias -Name {{cmd}}i -Value __zoxide_zi -Option AllScope -Scope Global -Force
{%- when None %} {%- when None %}