Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell: cd desk* Pattern Matching Doesn't Work Due to -LiteralPath #995

Open
benzaria opened this issue Feb 19, 2025 · 0 comments
Open

Comments

@benzaria
Copy link

Description

In PowerShell, cd desk* does not work as expected when using zoxide. Normally, PowerShell supports wildcard expansion in paths, but zoxide restricts this behavior. Instead of navigating to a matching directory (e.g., Desktop), it fails or does not expand the pattern.

Important

Upon reviewing the implementation, the issue seems to be caused by the use of the -LiteralPath parameter in the __zoxide_cd function. -LiteralPath prevents wildcard expansion, which explains why commands like cd desk* do not work.

Expected Behavior

PowerShell’s cd desk* should work similarly to its native behavior, where it matches a directory using wildcard expansion (e.g., resolving desk* to Desktop).

Actual Behavior

The command does not work as expected because zoxide uses Set-Location -LiteralPath, which prevents wildcard expansion.

Suspected Cause

The issue appears to be due to the __zoxide_cd function in the PowerShell integration:

# __zoxide_cd :
param($dir, $literal)
$dir = if ($literal) {
    Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop
} else {
   ...
}

Since -LiteralPath is used when $literal is true, it bypasses PowerShell's wildcard handling.

Suggested Fix

Consider modifying the function to allow wildcard expansion when applicable. Instead of -LiteralPath, using -Path should enable this functionality.
Or modify the function __zoxide_z, conditions to call __zoxide_cd with $literal = $false if the input contains wildcards.

# __zoxide_z :
...
 elseif ($args.Length -eq 1 -and ($args[0] -eq '-' -or $args[0] -eq '+')) {
        __zoxide_cd $args[0] $false
    }
    elseif ($args.Length -eq 1 -and (Test-Path $args[0] -PathType Container)) {
        __zoxide_cd $args[0] $true
    }
...

Environment

  • OS: Windows 11
  • PowerShell Version: 7.5.0
  • zoxide Version: 0.9.7

Additional Notes

  • This issue seems specific to PowerShell, as wildcard matching works differently in other shells (e.g., Bash).
  • If -LiteralPath is required for other use cases, an alternative could be to conditionally use -Path when the input contains wildcards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant