Improve error handling and portability
This commit is contained in:
parent
e58442cef2
commit
bc5c04b41c
|
|
@ -18,12 +18,9 @@ fn z(cmd: &str) -> String {
|
||||||
r#"
|
r#"
|
||||||
function {} {{
|
function {} {{
|
||||||
function z_cd($dir) {{
|
function z_cd($dir) {{
|
||||||
try {{
|
Set-Location $dir -ea Stop
|
||||||
Set-Location $dir -ea Stop
|
if ($env:_ZO_ECHO -eq "1") {{
|
||||||
if ($env:_ZO_ECHO -eq "1") {{
|
Write-Host "$PWD"
|
||||||
Write-Host "$PWD"
|
|
||||||
}}
|
|
||||||
}} catch {{
|
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
@ -35,7 +32,7 @@ function {} {{
|
||||||
}}
|
}}
|
||||||
else {{
|
else {{
|
||||||
$result = zoxide query @args
|
$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
|
z_cd $result
|
||||||
}} else {{
|
}} else {{
|
||||||
$result
|
$result
|
||||||
|
|
@ -74,8 +71,12 @@ function prompt {
|
||||||
|
|
||||||
const fn hook_pwd() -> Result<Cow<'static, str>> {
|
const fn hook_pwd() -> Result<Cow<'static, str>> {
|
||||||
const HOOK_PWD: &str = r#"
|
const HOOK_PWD: &str = r#"
|
||||||
$ExecutionContext.InvokeCommand.LocationChangedAction = {
|
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
||||||
$null = zoxide add
|
$ExecutionContext.InvokeCommand.LocationChangedAction = {
|
||||||
|
$null = zoxide add
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Error "pwd hook requires pwsh - use 'zoxide init powershell --hook prompt'"
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue