ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.29k stars 518 forks source link

.zoxide.nu method breaks with the latest 0.94.0 release #831

Closed dazfuller closed 1 month ago

dazfuller commented 1 month ago

The changes in the latest release of nu has broken the generated __zoxide_z in the .zoxide.nu file as the path type command now throws an error if the file/dir does not exist.

I've gotten it working again in my local environment by changing the command to the following

# Jump to a directory using only keywords.
def --env __zoxide_z [...rest:string] {
  let arg0 = ($rest | append '~').0
  let path = if (($rest | length) <= 1) and ($arg0 == '-' or (($arg0 | path expand | path exists) and ($arg0 | path expand | path type) == dir)) {
    $arg0
  } else {
    (zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
  }
  cd $path
}

This way it explicitly checks if the path exists before checking it's type. Not sure if there's an easier way to do it as my NuShell scripting isn't that great.

paulhey commented 1 month ago

So I ran into this issue this morning as well, I think I have something that works but it's ugly:

# Jump to a directory using only keywords.
def --env __zoxide_z [...rest:string] {
  let arg0 = ($rest | append '~').0
  # Expand the path first
  let arg_path = ($arg0 | path expand)
  # First check if the path exists before checking it's a directory
  let path = if (($rest | length) <= 1) and ($arg0 == '-' or (($arg_path | path exists) and ($arg_path | path type) == dir)) {
    $arg0
  } else {
    (zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
  }
  cd $path
}
paulhey commented 1 month ago

Looks like there's already a fix in place.

dazfuller commented 1 month ago

Damn, fixed before I'd hit brew update this morning 😆

Gonna close this then as it's all in hand