Support Nushell 0.32.0 (#219)

This commit is contained in:
Ajeet D'Souza 2021-06-03 02:49:21 +05:30 committed by GitHub
parent fcdfb19fd1
commit 36f3967f9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 36 deletions

View File

@ -12,11 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Auto-generated shell completions. - Auto-generated shell completions.
- `zoxide query --all` for listing deleted directories. - `zoxide query --all` for listing deleted directories.
- Lazy deletion for removed directories that have not been accessed in > 90 days. - Lazy deletion for removed directories that have not been accessed in > 90 days.
- Nushell: support for 0.32.0+.
### Fixed ### Fixed
- Nushell: avoid calling `__zoxide_hook` on non-filesystem subshells. - 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. - PowerShell: avoid calling `__zoxide_hook` on non-filesystem providers.
- Fish: avoid calling `__zoxide_hook` in private mode. - Fish: avoid calling `__zoxide_hook` in private mode.

View File

@ -127,7 +127,7 @@ Add this to your configuration (usually `~/.config/fish/config.fish`):
zoxide init fish | source zoxide init fish | source
``` ```
#### `nushell` #### `nushell 0.32.0+`
Initialize zoxide's Nushell script: Initialize zoxide's Nushell script:

View File

@ -78,9 +78,7 @@ impl<'file> Database<'file> {
let rank = curr_dir.rank; let rank = curr_dir.rank;
let last_accessed = curr_dir.last_accessed; let last_accessed = curr_dir.last_accessed;
let next_dir = &mut self.dirs[idx - 1]; let next_dir = &mut self.dirs[idx - 1];
if next_dir.last_accessed < last_accessed { next_dir.last_accessed = next_dir.last_accessed.max(last_accessed);
next_dir.last_accessed = last_accessed;
}
next_dir.rank += rank; next_dir.rank += rank;
// Delete curr_dir. // Delete curr_dir.

View File

@ -171,6 +171,7 @@ mod tests {
.stderr(""); .stderr("");
} }
#[ignore]
#[rstest] #[rstest]
fn nushell_nushell( fn nushell_nushell(
#[values(None, Some("z"))] cmd: Option<&str>, #[values(None, Some("z"))] cmd: Option<&str>,

View File

@ -1,15 +1,19 @@
{%- let section = "# =============================================================================\n#" -%} {%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%} {%- let not_configured = "# -- not configured --" -%}
{%- let newline = "{{$(char newline)}}" -%}
{{ section }} {{ section }}
# Utility functions for zoxide. # Utility functions for zoxide.
# #
# Default prompt for Nushell. # Default prompt for Nushell.
# Taken from: <https://github.com/nushell/nushell/blob/main/docs/sample_config/config.toml>
def __zoxide_prompt [] { 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 }} {{ section }}
@ -28,7 +32,7 @@ def __zoxide_hook [] {
{%- when InitHook::Pwd %} {%- when InitHook::Pwd %}
def __zoxide_hook [] {} 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 %} {%- endmatch %}
{{ section }} {{ section }}
@ -38,34 +42,21 @@ echo `zoxide: PWD hooks are not supported on Nushell.{{ newline }} Use 'z
# Jump to a directory using only keywords. # Jump to a directory using only keywords.
def __zoxide_z [...rest:string] { def __zoxide_z [...rest:string] {
let args = $(echo $rest | skip 1); if (shells | where active == $true | get name) != filesystem {
if $(shells | where active == $true | get name) != filesystem { if (echo $rest | length) > 1 {
if $(echo $args | length) > 1 { $"zoxide: can only jump directories on filesystem(char nl)"
echo `zoxide: can only jump directories on filesystem{{ newline }}`
} { } {
cd $(echo $args) cd (echo $rest)
{%- if echo %} {%- if echo %}
pwd pwd
{%- endif %} {%- endif %}
} }
} { } {
if $(echo $args | length) == 0 { let arg0 = (echo $rest | append '~' | first 1);
cd ~ if (echo $rest | length) <= 1 && ($arg0 == '-' || (echo $arg0 | path expand | path exists)) {
cd $arg0
} { } {
if $(echo $args | length) == 1 { cd (zoxide query --exclude (pwd) -- $rest | str trim)
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)
}
} }
{%- if echo %} {%- if echo %}
pwd pwd
@ -75,11 +66,10 @@ def __zoxide_z [...rest:string] {
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
def __zoxide_zi [...rest:string] { def __zoxide_zi [...rest:string] {
if $(shells | where active == $true | get name) != filesystem { if (shells | where active == $true | get name) != filesystem {
echo `zoxide: can only jump directories on filesystem{{ newline }}` $"zoxide: can only jump directories on filesystem(char nl)"
} { } {
let args = $(echo $rest | skip 1) cd (zoxide query -i -- $rest | str trim)
cd $(zoxide query -i -- $args | str trim)
{%- if echo %} {%- if echo %}
pwd pwd
{%- endif %} {%- endif %}
@ -93,8 +83,8 @@ def __zoxide_zi [...rest:string] {
{%- match cmd %} {%- match cmd %}
{%- when Some with (cmd) %} {%- when Some with (cmd) %}
alias {{cmd}} = __zoxide_z '' alias {{cmd}} = __zoxide_z
alias {{cmd}}i = __zoxide_zi '' alias {{cmd}}i = __zoxide_zi
{%- when None %} {%- when None %}