diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ab519..c396d61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Auto-generated shell completions. - `zoxide query --all` for listing deleted directories. - Lazy deletion for removed directories that have not been accessed in > 90 days. +- Nushell: support for 0.32.0+. ### Fixed - Nushell: avoid calling `__zoxide_hook` on non-filesystem subshells. -- `alias cd=z` now works on Fish, but it must be done after calling `zoxide init`. +- Fish: `alias cd=z` now works, but it must be done after calling `zoxide init`. - PowerShell: avoid calling `__zoxide_hook` on non-filesystem providers. - Fish: avoid calling `__zoxide_hook` in private mode. diff --git a/README.md b/README.md index 123fac2..f3e9785 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Add this to your configuration (usually `~/.config/fish/config.fish`): zoxide init fish | source ``` -#### `nushell` +#### `nushell 0.32.0+` Initialize zoxide's Nushell script: diff --git a/src/db/mod.rs b/src/db/mod.rs index 1d458ac..05f1f1e 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -78,9 +78,7 @@ impl<'file> Database<'file> { let rank = curr_dir.rank; let last_accessed = curr_dir.last_accessed; let next_dir = &mut self.dirs[idx - 1]; - if next_dir.last_accessed < last_accessed { - next_dir.last_accessed = last_accessed; - } + next_dir.last_accessed = next_dir.last_accessed.max(last_accessed); next_dir.rank += rank; // Delete curr_dir. diff --git a/src/shell.rs b/src/shell.rs index 8a3ef78..1500e6b 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -171,6 +171,7 @@ mod tests { .stderr(""); } + #[ignore] #[rstest] fn nushell_nushell( #[values(None, Some("z"))] cmd: Option<&str>, diff --git a/templates/nushell.txt b/templates/nushell.txt index 301e6c7..217ab4a 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -1,15 +1,19 @@ {%- let section = "# =============================================================================\n#" -%} {%- let not_configured = "# -- not configured --" -%} -{%- let newline = "{{$(char newline)}}" -%} {{ section }} # Utility functions for zoxide. # # Default prompt for Nushell. -# Taken from: def __zoxide_prompt [] { - build-string $(ansi gb) $(pwd) $(ansi reset) '(' $(ansi cb) $(do -i { git rev-parse --abbrev-ref HEAD } | str trim) $(ansi reset) ')' $(ansi yb) $(date format '%m/%d/%Y %I:%M:%S%.3f %p') $(ansi reset) '> ' + let git = $"(do -i {git rev-parse --abbrev-ref HEAD} | str trim)" + let git = (if (echo $git | str length) == 0 { + "" + } { + build-string (char lparen) (ansi cb) $git (ansi reset) (char rparen) + }) + build-string (ansi gb) (pwd) (ansi reset) $git "> " } {{ section }} @@ -28,7 +32,7 @@ def __zoxide_hook [] { {%- when InitHook::Pwd %} def __zoxide_hook [] {} -echo `zoxide: PWD hooks are not supported on Nushell.{{ newline }} Use 'zoxide init nushell --hook prompt' instead.{{ newline }}` +$"zoxide: PWD hooks are not supported on Nushell.(char nl)Use 'zoxide init nushell --hook prompt' instead.(char nl)" {%- endmatch %} {{ section }} @@ -38,34 +42,21 @@ echo `zoxide: PWD hooks are not supported on Nushell.{{ newline }} Use 'z # Jump to a directory using only keywords. def __zoxide_z [...rest:string] { - let args = $(echo $rest | skip 1); - if $(shells | where active == $true | get name) != filesystem { - if $(echo $args | length) > 1 { - echo `zoxide: can only jump directories on filesystem{{ newline }}` + if (shells | where active == $true | get name) != filesystem { + if (echo $rest | length) > 1 { + $"zoxide: can only jump directories on filesystem(char nl)" } { - cd $(echo $args) + cd (echo $rest) {%- if echo %} pwd {%- endif %} } } { - if $(echo $args | length) == 0 { - cd ~ + let arg0 = (echo $rest | append '~' | first 1); + if (echo $rest | length) <= 1 && ($arg0 == '-' || (echo $arg0 | path expand | path exists)) { + cd $arg0 } { - if $(echo $args | length) == 1 { - let arg0 = $(echo $args | first 1); - if $arg0 == '-' { - cd - - } { - if $(echo $arg0 | path exists) { - cd $arg0 - } { - cd $(zoxide query --exclude $(pwd) -- $args | str trim) - } - } - } { - cd $(zoxide query --exclude $(pwd) -- $args | str trim) - } + cd (zoxide query --exclude (pwd) -- $rest | str trim) } {%- if echo %} pwd @@ -75,11 +66,10 @@ def __zoxide_z [...rest:string] { # Jump to a directory using interactive search. def __zoxide_zi [...rest:string] { - if $(shells | where active == $true | get name) != filesystem { - echo `zoxide: can only jump directories on filesystem{{ newline }}` + if (shells | where active == $true | get name) != filesystem { + $"zoxide: can only jump directories on filesystem(char nl)" } { - let args = $(echo $rest | skip 1) - cd $(zoxide query -i -- $args | str trim) + cd (zoxide query -i -- $rest | str trim) {%- if echo %} pwd {%- endif %} @@ -93,8 +83,8 @@ def __zoxide_zi [...rest:string] { {%- match cmd %} {%- when Some with (cmd) %} -alias {{cmd}} = __zoxide_z '' -alias {{cmd}}i = __zoxide_zi '' +alias {{cmd}} = __zoxide_z +alias {{cmd}}i = __zoxide_zi {%- when None %}