Add support for Nushell (#164)

This commit is contained in:
Ajeet D'Souza 2021-03-31 22:15:43 +05:30 committed by GitHub
parent e2506631e9
commit d9c0584aac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 171 additions and 56 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

4
Cargo.lock generated
View File

@ -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"

View File

@ -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)

View File

@ -1,5 +1,3 @@
<!-- omit in toc -->
# 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
<!-- omit in toc -->
## 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`.
<!-- omit in toc -->
#### 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` |
<!-- omit in toc -->
#### 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` |
<!-- omit in toc -->
#### 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` |
<!-- omit in toc -->
#### 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` |
<!-- omit in toc -->
#### 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
```
<!-- omit in toc -->
#### bash
Add the following line to your `~/.bashrc`:
@ -137,19 +118,30 @@ Add the following line to your `~/.bashrc`:
eval "$(zoxide init bash)"
```
<!-- omit in toc -->
#### fish
Add the following line to your `~/.config/fish/config.fish`:
```sh
```fish
zoxide init fish | source
```
<!-- omit in toc -->
#### 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 (& {
})
```
<!-- omit in toc -->
#### xonsh
Add the following line to your profile (usually `~/.xonshrc`):
```xonsh
```python
execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
```
<!-- omit in toc -->
#### zsh
Add the following line to your `~/.zshrc`:
@ -180,8 +168,6 @@ Add the following line to your `~/.zshrc`:
eval "$(zoxide init zsh)"
```
<!-- omit in toc -->
#### 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:

View File

@ -14,6 +14,7 @@ pkgs.mkShell {
pkgs.fish
pkgs.fzf
pkgs.git
# pkgs.nushell # FIXME: too outdated
pkgs.powershell
pkgs.rustc
pkgs.shellcheck

View File

@ -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,

View File

@ -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()

95
templates/nushell.txt Normal file
View File

@ -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`

View File

@ -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" })