From bc5c04b41c8e158e1da3db4c1d0f48cee3ae5299 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Tue, 5 May 2020 22:52:51 -0700 Subject: [PATCH] Improve error handling and portability --- src/subcommand/init/shell/powershell.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/subcommand/init/shell/powershell.rs b/src/subcommand/init/shell/powershell.rs index f33ac54..142dd7e 100644 --- a/src/subcommand/init/shell/powershell.rs +++ b/src/subcommand/init/shell/powershell.rs @@ -18,12 +18,9 @@ fn z(cmd: &str) -> String { r#" function {} {{ function z_cd($dir) {{ - try {{ - Set-Location $dir -ea Stop - if ($env:_ZO_ECHO -eq "1") {{ - Write-Host "$PWD" - }} - }} catch {{ + Set-Location $dir -ea Stop + if ($env:_ZO_ECHO -eq "1") {{ + Write-Host "$PWD" }} }} @@ -35,7 +32,7 @@ function {} {{ }} else {{ $result = zoxide query @args - if ($LASTEXITCODE -eq 0 -and ((Test-Path $result) -eq $true)) {{ + if ($LASTEXITCODE -eq 0 -and $result -is [string] -and (Test-Path $result)) {{ z_cd $result }} else {{ $result @@ -74,8 +71,12 @@ function prompt { const fn hook_pwd() -> Result> { const HOOK_PWD: &str = r#" -$ExecutionContext.InvokeCommand.LocationChangedAction = { - $null = zoxide add +if ($PSVersionTable.PSVersion.Major -ge 6) { + $ExecutionContext.InvokeCommand.LocationChangedAction = { + $null = zoxide add + } +} else { + Write-Error "pwd hook requires pwsh - use 'zoxide init powershell --hook prompt'" } "#;