diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 389d06b..40695f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,11 @@ jobs: with: crate: cargo-audit version: latest + - uses: actions-rs/install@v0.1 + if: ${{ matrix.os != 'windows-latest' }} + with: + crate: nu + version: latest - uses: cachix/install-nix-action@v12 if: ${{ matrix.os != 'windows-latest' }} with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8dcfeeb..32f3f85 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,17 @@ on: push: tags: - - "v*" # push events to matching v*, i.e. v1.0, v20.15.10 + - "v*" jobs: build-linux: runs-on: ubuntu-latest strategy: matrix: - target: ["x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "armv7-unknown-linux-musleabihf"] + target: + - "x86_64-unknown-linux-gnu" + - "x86_64-unknown-linux-musl" + - "armv7-unknown-linux-musleabihf" steps: - uses: actions/checkout@v2 - uses: actions-rs/cargo@v1 @@ -46,7 +49,7 @@ jobs: with: name: "zoxide-x86_64-pc-windows-msvc" path: "target/x86_64-pc-windows-msvc/release/zoxide.exe" - + release-upload: needs: - build-linux diff --git a/CHANGELOG.md b/CHANGELOG.md index a0fe6f1..c6b60ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Support for [Nushell](https://www.nushell.sh/). + ### Fixed - Removed backtraces on Rust nightly. @@ -14,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Handle broken pipe errors gracefully when writing to streams. - NUL file appearing in working directory on Windows. - Accidental redefinition of hooks when initialized twice on some shells. +- zoxide unable to find itself on Xonsh shells. ### Removed @@ -69,7 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Support for PowerShell. +- Support for powershell. ### Removed diff --git a/Cargo.lock b/Cargo.lock index 7e6e92d..c380296 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -295,9 +295,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" +checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" [[package]] name = "memchr" diff --git a/Makefile b/Makefile index eaa5007..f0cd743 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif ifeq ($(NIX), true) build: - nix-shell --pure --run 'cargo build $(build_flags) $(ci_color_always)' + nix-shell --run 'cargo build $(build_flags) $(ci_color_always)' else build: cargo build $(build_flags) $(ci_color_always) @@ -24,7 +24,7 @@ endif ifeq ($(NIX), true) clean: - nix-shell --pure --run 'cargo clean $(ci_color_always)' + nix-shell --run 'cargo clean $(ci_color_always)' else clean: cargo clean $(ci_color_always) @@ -32,7 +32,7 @@ endif ifeq ($(NIX), true) install: - nix-shell --pure --run 'cargo install --path=. $(ci_color_always)' + nix-shell --run 'cargo install --path=. $(ci_color_always)' else install: cargo install --path=. $(ci_color_always) @@ -40,23 +40,23 @@ endif ifeq ($(NIX), true) test: - nix-shell --pure --run 'cargo fmt -- --check --files-with-diff $(ci_color_always)' - nix-shell --pure --run 'cargo check --all-features $(ci_color_always)' - nix-shell --pure --run 'cargo clippy --all-features $(ci_color_always) -- --deny warnings --deny clippy::all' - nix-shell --pure --run 'cargo test --all-features --no-fail-fast $(ci_color_always)' - nix-shell --pure --run 'cargo audit --deny warnings $(ci_color_always) --ignore=RUSTSEC-2020-0095' + nix-shell --run 'cargo fmt -- --check --files-with-diff $(ci_color_always)' + nix-shell --run 'cargo check --all-features $(build_flags) $(ci_color_always)' + nix-shell --run 'cargo clippy --all-features $(build_flags) $(ci_color_always) -- --deny warnings --deny clippy::all' + nix-shell --run 'cargo test --all-features --no-fail-fast $(build_flags) $(ci_color_always)' + nix-shell --run 'cargo audit --deny warnings $(ci_color_always) --ignore=RUSTSEC-2020-0095' else test: cargo fmt -- --check --files-with-diff $(ci_color_always) - cargo check --all-features $(ci_color_always) - cargo clippy --all-features $(ci_color_always) -- --deny warnings --deny clippy::all - cargo test --no-fail-fast $(ci_color_always) + cargo check --all-features $(build_flags) $(ci_color_always) + cargo clippy --all-features $(build_flags) $(ci_color_always) -- --deny warnings --deny clippy::all + cargo test --no-fail-fast $(build_flags) $(ci_color_always) cargo audit --deny warnings $(ci_color_always) --ignore=RUSTSEC-2020-0095 endif ifeq ($(NIX), true) uninstall: - nix-shell --pure --run 'cargo uninstall $(ci_color_always)' + nix-shell --run 'cargo uninstall $(ci_color_always)' else uninstall: cargo uninstall $(ci_color_always) diff --git a/README.md b/README.md index 3a8e48f..cce127c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ - - # zoxide [![crates.io](https://img.shields.io/crates/v/zoxide)](https://crates.io/crates/zoxide) @@ -7,16 +5,11 @@ A faster way to navigate your filesystem - - ## Table of contents - [Introduction](#introduction) - [Examples](#examples) - [Getting started](#getting-started) - - [Step 1: Install zoxide](#step-1-install-zoxide) - - [Step 2: Install fzf (optional)](#step-2-install-fzf-optional) - - [Step 3: Add zoxide to your shell](#step-3-add-zoxide-to-your-shell) - [Configuration](#configuration) ## Introduction @@ -51,8 +44,6 @@ curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ajeetdsou If you would rather not run a script, you can download the binary from the [Releases](https://github.com/ajeetdsouza/zoxide/releases) page and add it anywhere in your `$PATH`. - - #### On Linux | Distribution | Repository | Instructions | @@ -68,8 +59,6 @@ If you would rather not run a script, you can download the binary from the [Rele | Parrot OS | | `apt install zoxide` | | Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` | - - #### On macOS | Repository | Instructions | @@ -78,8 +67,6 @@ If you would rather not run a script, you can download the binary from the [Rele | [Homebrew] | `brew install zoxide` | | [MacPorts] | `port install zoxide` | - - #### On Windows | Repository | Instructions | @@ -87,8 +74,6 @@ If you would rather not run a script, you can download the binary from the [Rele | [crates.io] | `cargo install zoxide` | | [Scoop] | `scoop install zoxide` | - - #### On BSD | Distribution | Repository | Instructions | @@ -98,8 +83,6 @@ If you would rather not run a script, you can download the binary from the [Rele | FreeBSD | [FreshPorts] | `pkg install zoxide` | | NetBSD | [pkgsrc] | `pkgin install zoxide` | - - #### On Android | Repository | Instructions | @@ -118,7 +101,7 @@ If you currently use `z`, `z.lua`, or `zsh-z`, you may want to first import your existing entries into `zoxide`: ```sh -zoxide import /path/to/db +zoxide import --from z /path/to/db ``` Alternatively, for `autojump`: @@ -127,8 +110,6 @@ Alternatively, for `autojump`: zoxide import --from autojump /path/to/db ``` - - #### bash Add the following line to your `~/.bashrc`: @@ -137,19 +118,30 @@ Add the following line to your `~/.bashrc`: eval "$(zoxide init bash)" ``` - - #### fish Add the following line to your `~/.config/fish/config.fish`: -```sh +```fish zoxide init fish | source ``` - +#### nushell -#### PowerShell +Initialize zoxide's Nushell script: + +```sh +zoxide init nushell --hook prompt | save ~/.zoxide.nu +``` + +Then, in your Nushell configuration file: + +- Prepend `__zoxide_hook;` to the `prompt` variable. +- Add the following lines to the `startup` variable: + - `zoxide init nushell --hook prompt | save ~/.zoxide.nu` + - `source ~/.zoxide.nu` + +#### powershell Add the following line to your profile: @@ -160,18 +152,14 @@ Invoke-Expression (& { }) ``` - - #### xonsh Add the following line to your profile (usually `~/.xonshrc`): -```xonsh +```python execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') ``` - - #### zsh Add the following line to your `~/.zshrc`: @@ -180,8 +168,6 @@ Add the following line to your `~/.zshrc`: eval "$(zoxide init zsh)" ``` - - #### Any POSIX shell Add the following line to your shell's configuration file: @@ -205,6 +191,8 @@ eval "$(zoxide init posix --hook prompt)" ### Environment variables +Be sure to set these before calling `zoxide init`. + - `_ZO_DATA_DIR` - Specifies the directory in which zoxide should store its database. - The default value varies across OSes: diff --git a/shell.nix b/shell.nix index e6e11a2..8d53eb3 100644 --- a/shell.nix +++ b/shell.nix @@ -14,6 +14,7 @@ pkgs.mkShell { pkgs.fish pkgs.fzf pkgs.git + # pkgs.nushell # FIXME: too outdated pkgs.powershell pkgs.rustc pkgs.shellcheck diff --git a/src/cmd/init.rs b/src/cmd/init.rs index b0e24d4..d425a7c 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -51,8 +51,9 @@ impl Cmd for Init { let source = match self.shell { Shell::Bash => shell::Bash(opts).render(), Shell::Fish => shell::Fish(opts).render(), + Shell::Nushell => shell::Nushell(opts).render(), Shell::Posix => shell::Posix(opts).render(), - Shell::Powershell => shell::PowerShell(opts).render(), + Shell::Powershell => shell::Powershell(opts).render(), Shell::Xonsh => shell::Xonsh(opts).render(), Shell::Zsh => shell::Zsh(opts).render(), } @@ -65,6 +66,7 @@ impl Cmd for Init { enum Shell { Bash, Fish, + Nushell, Posix, Powershell, Xonsh, diff --git a/src/shell.rs b/src/shell.rs index 56f087d..d012bbe 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -25,8 +25,9 @@ macro_rules! make_template { make_template!(Bash, "bash.txt"); make_template!(Fish, "fish.txt"); +make_template!(Nushell, "nushell.txt"); make_template!(Posix, "posix.txt"); -make_template!(PowerShell, "powershell.txt"); +make_template!(Powershell, "powershell.txt"); make_template!(Xonsh, "xonsh.txt"); make_template!(Zsh, "zsh.txt"); @@ -152,6 +153,21 @@ mod tests { // TODO: fishindent + #[test] + fn nushell_nushell_#i() { + let opts = dbg!(&opts()[i]); + let source = Nushell(opts).render().unwrap(); + let assert = Command::new("nu") + .args(&["--commands", &source]) + .assert() + .success() + .stderr(""); + + if opts.hook != Hook::Pwd { + assert.stdout(""); + } + } + #[test] fn posix_bashposix_#i() { let opts = dbg!(&opts()[i]); @@ -214,7 +230,7 @@ mod tests { #[test] fn powershell_pwsh_#i() { let opts = dbg!(&opts()[i]); - let source = PowerShell(opts).render().unwrap(); + let source = Powershell(opts).render().unwrap(); Command::new("pwsh") .args(&["-Command", &source, "-NoLogo", "-NonInteractive", "-NoProfile"]) .assert() diff --git a/templates/nushell.txt b/templates/nushell.txt new file mode 100644 index 0000000..c3ab8ea --- /dev/null +++ b/templates/nushell.txt @@ -0,0 +1,95 @@ +{%- let SECTION = "# =============================================================================\n#" -%} +{%- let NOT_CONFIGURED = "# -- not configured --" -%} + +{{ SECTION }} +# Hook configuration for zoxide. +# + +# Hook to add new entries to the database. +{%- match hook %} +{%- when Hook::None %} +def __zoxide_hook [] {} + +{%- when Hook::Prompt %} +def __zoxide_hook [] { + zoxide add "$(pwd)" +} + +{%- when Hook::Pwd %} +def __zoxide_hook [] {} + +printf "zoxide: PWD hooks are not supported on Nushell.\n Use 'zoxide init nushell --hook prompt' instead.\n" + +def __zoxide_hook [] { + zoxide add "$(pwd)" +} + +{%- endmatch %} + +{{ SECTION }} +# When using zoxide with --no-aliases, alias these internal functions as +# desired. +# + +# Jump to a directory using only keywords. +def __zoxide_z [...rest:string] { + if $(echo $rest | length) == 1 { + cd ~ + } { + let args = $(echo $rest | skip 1); + if $(echo $args | length) == 1 { + let arg0 = $(echo $args | first 1); + if $arg0 == '-' { + cd - + } { + if $(echo $arg0 | path exists) { + cd $arg0 + } { + cd $(zoxide query -- $args | str trim) + } + } + } { + cd $(zoxide query -- $args | str trim) + } + } + {%- if echo %} + echo $(pwd) + {%- endif %} +} + +# Jump to a directory using interactive search. +def __zoxide_zi [...rest:string] { + let args = $(echo $rest | skip 1) + cd $(zoxide query -i -- $args | str trim) + {%- if echo %} + echo $(pwd) + {%- endif %} +} + +{{ SECTION }} +# Convenient aliases for zoxide. Disable these using --no-aliases. +# + +{%- match cmd %} +{%- when Some with (cmd) %} + +alias {{cmd}} = __zoxide_z '' +alias {{cmd}}i = __zoxide_zi '' + +{%- when None %} +{{ NOT_CONFIGURED }} + +{%- endmatch %} + +{{ SECTION }} +# To initialize zoxide with Nushell: +# +# Initialize zoxide's Nushell script: +# +# zoxide init nushell --hook prompt | save ~/.zoxide.nu +# +# Then, in your Nushell configuration file: +# - Prepend `__zoxide_hook;` to the `prompt` variable. +# - Add the following lines to the `startup` variable: +# - `zoxide init nushell --hook prompt | save ~/.zoxide.nu` +# - `source ~/.zoxide.nu` diff --git a/templates/powershell.txt b/templates/powershell.txt index e766d48..9e72391 100644 --- a/templates/powershell.txt +++ b/templates/powershell.txt @@ -46,7 +46,7 @@ if ($__zoxide_hooked -ne '1') { } } else { Write-Error ("`n" + - "zoxide: PWD hooks are not supported below PowerShell 6.`n" + + "zoxide: PWD hooks are not supported below powershell 6.`n" + " Use 'zoxide init powershell --hook prompt' instead.") } {%- endmatch %} @@ -100,7 +100,7 @@ Set-Alias {{cmd}}i __zoxide_zi {%- endmatch %} {{ SECTION }} -# To initialize zoxide with PowerShell, add the following line to your -# PowerShell configuration file (the location is stored in $profile): +# To initialize zoxide with powershell, add the following line to your +# powershell configuration file (the location is stored in $profile): # # Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -ge 6) { 'pwd' } else { 'prompt' } (zoxide init powershell --hook $hook) -join "`n" })