Version checks for cd +/-

This commit is contained in:
Ajeet D'Souza 2023-05-06 19:18:48 +05:30
parent 3904026d74
commit 76af954af3
1 changed files with 10 additions and 2 deletions

View File

@ -30,7 +30,15 @@ function __zoxide_cd($dir, $literal) {
$dir = if ($literal) { $dir = if ($literal) {
Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop
} else { } else {
Set-Location -Path $dir -Passthru -ErrorAction Stop if ($dir -eq '-' -and ($PSVersionTable.PSVersion -ge 6.1)) {
Write-Error "cd - is not supported below PowerShell 6.1. Please upgrade your version of PowerShell."
}
elseif ($dir -eq '+' -and ($PSVersionTable.PSVersion -ge 6.2)) {
Write-Error "cd + is not supported below PowerShell 6.2. Please upgrade your version of PowerShell."
}
else {
Set-Location -Path $dir -Passthru -ErrorAction Stop
}
} }
{%- if echo %} {%- if echo %}
Write-Output $dir.Path Write-Output $dir.Path
@ -74,7 +82,7 @@ if ($__zoxide_hooked -ne 1) {
} }
else { else {
Write-Error ("`n" + Write-Error ("`n" +
"zoxide: PWD hooks are not supported below powershell 6.`n" + "zoxide: PWD hooks are not supported below PowerShell 6.`n" +
" Use 'zoxide init powershell --hook prompt' instead.") " Use 'zoxide init powershell --hook prompt' instead.")
} }
{%- endmatch %} {%- endmatch %}