Merge branch 'main' into custom-completer

This commit is contained in:
Yash Thakur 2025-06-07 22:15:05 -04:00 committed by GitHub
commit e516852566
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 416 additions and 446 deletions

View File

@ -7,17 +7,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased ## [0.9.8] - 2025-05-27
### Added ### Added
- Support for Tcsh. - Support for Tcsh.
- Added `--score` flag to `zoxide add`. - Added `--score` flag to `zoxide add`.
- POSIX: add doctor to diagnose common issues. - POSIX: add doctor to diagnose common issues.
- Nushell: add CLI completions.
### Changed ### Changed
- Bash: zoxide will now rewrite the prompt when using Space-Tab completions. - Bash: zoxide will now automatically `cd` when selecting Space-Tab completions.
### Fixed ### Fixed
@ -27,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Nushell: stop ignoring symlinks when `cd`-ing into a directory. - Nushell: stop ignoring symlinks when `cd`-ing into a directory.
- Fzf: updated minimum supported version to v0.51.0. - Fzf: updated minimum supported version to v0.51.0.
- PowerShell: avoid setting `$error` when defining `__zoxide_hooked`. - PowerShell: avoid setting `$error` when defining `__zoxide_hooked`.
- PowerShell: handle special characters in file paths when `cd`-ing into them.
- Database corruption issue when the filesystem is 100% full.
## [0.9.7] - 2025-02-10 ## [0.9.7] - 2025-02-10
@ -533,6 +536,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- GitHub Actions pipeline to build and upload releases. - GitHub Actions pipeline to build and upload releases.
- Add support for Zsh. - Add support for Zsh.
[0.9.8]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.7...v0.9.8
[0.9.7]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.6...v0.9.7 [0.9.7]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.6...v0.9.7
[0.9.6]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.5...v0.9.6 [0.9.6]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.5...v0.9.6
[0.9.5]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.4...v0.9.5 [0.9.5]: https://github.com/ajeetdsouza/zoxide/compare/v0.9.4...v0.9.5

620
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,44 +10,48 @@ name = "zoxide"
readme = "README.md" readme = "README.md"
repository = "https://github.com/ajeetdsouza/zoxide" repository = "https://github.com/ajeetdsouza/zoxide"
rust-version = "1.85.0" rust-version = "1.85.0"
version = "0.9.7" version = "0.9.8"
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
anyhow = "1.0.32" anyhow = "1.0.32"
askama = { version = "0.14.0", default-features = false, features = [
"derive",
"std",
] }
bincode = "1.3.1" bincode = "1.3.1"
clap = { version = "4.3.0", features = ["derive"] } clap = { version = "4.3.0", features = ["derive"] }
color-print = "0.3.4" color-print = "0.3.4"
dirs = "5.0.0" dirs = "6.0.0"
dunce = "1.0.1" dunce = "1.0.1"
fastrand = "2.0.0" fastrand = "2.0.0"
glob = "0.3.0" glob = "0.3.0"
ouroboros = "0.18.3" ouroboros = "0.18.3"
rinja = { version = "0.3.2", default-features = false }
serde = { version = "1.0.116", features = ["derive"] } serde = { version = "1.0.116", features = ["derive"] }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = { version = "0.29.0", default-features = false, features = [ nix = { version = "0.30.1", default-features = false, features = [
"fs", "fs",
"user", "user",
] } ] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
which = "6.0.0" which = "7.0.3"
[build-dependencies] [build-dependencies]
clap = { version = "4.3.0", features = ["derive"] } clap = { version = "4.3.0", features = ["derive"] }
clap_complete = "4.3.0" clap_complete = "4.5.50"
clap_complete_fig = "4.3.0" clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.5"
color-print = "0.3.4" color-print = "0.3.4"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2.0.0" assert_cmd = "2.0.0"
rstest = { version = "0.23.0", default-features = false } rstest = { version = "0.25.0", default-features = false }
rstest_reuse = "0.7.0" rstest_reuse = "0.7.0"
tempfile = "3.1.0" tempfile = "=3.15.0"
[features] [features]
default = [] default = []

View File

@ -86,34 +86,35 @@ zoxide can be installed in 4 easy steps:
> >
> Or, you can use a package manager: > Or, you can use a package manager:
> >
> | Distribution | Repository | Instructions | > | Distribution | Repository | Instructions |
> | ------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------- | > | ------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------- |
> | **_Any_** | **[crates.io]** | `cargo install zoxide --locked` | > | **_Any_** | **[crates.io]** | `cargo install zoxide --locked` |
> | _Any_ | [asdf] | `asdf plugin add zoxide https://github.com/nyrst/asdf-zoxide.git` <br /> `asdf install zoxide latest` | > | _Any_ | [asdf] | `asdf plugin add zoxide https://github.com/nyrst/asdf-zoxide.git` <br /> `asdf install zoxide latest` |
> | _Any_ | [conda-forge] | `conda install -c conda-forge zoxide` | > | _Any_ | [conda-forge] | `conda install -c conda-forge zoxide` |
> | _Any_ | [guix] | `guix install zoxide` | > | _Any_ | [guix] | `guix install zoxide` |
> | _Any_ | [Linuxbrew] | `brew install zoxide` | > | _Any_ | [Linuxbrew] | `brew install zoxide` |
> | _Any_ | [nixpkgs] | `nix-env -iA nixpkgs.zoxide` | > | _Any_ | [nixpkgs] | `nix-env -iA nixpkgs.zoxide` |
> | AlmaLinux | | `dnf install zoxide` | > | AlmaLinux | | `dnf install zoxide` |
> | Alpine Linux 3.13+ | [Alpine Linux Packages] | `apk add zoxide` | > | Alpine Linux 3.13+ | [Alpine Linux Packages] | `apk add zoxide` |
> | Arch Linux | [Arch Linux Extra] | `pacman -S zoxide` | > | Arch Linux | [Arch Linux Extra] | `pacman -S zoxide` |
> | CentOS Stream | | `dnf install zoxide` | > | CentOS Stream | | `dnf install zoxide` |
> | ~Debian 11+~[^1] | ~[Debian Packages]~ | ~`apt install zoxide`~ | > | ~Debian 11+~[^1] | ~[Debian Packages]~ | ~`apt install zoxide`~ |
> | Devuan 4.0+ | [Devuan Packages] | `apt install zoxide` | > | Devuan 4.0+ | [Devuan Packages] | `apt install zoxide` |
> | Exherbo Linux | [Exherbo packages] | `cave resolve -x repository/rust` <br /> `cave resolve -x zoxide` | > | Exherbo Linux | [Exherbo packages] | `cave resolve -x repository/rust` <br /> `cave resolve -x zoxide` |
> | Fedora 32+ | [Fedora Packages] | `dnf install zoxide` | > | Fedora 32+ | [Fedora Packages] | `dnf install zoxide` |
> | Gentoo | [Gentoo Packages] | `emerge app-shells/zoxide` | > | Gentoo | [Gentoo Packages] | `emerge app-shells/zoxide` |
> | Manjaro | | `pacman -S zoxide` | > | Linux Mint | [apt.cli.rs] (unofficial) | [Setup the repository][apt.cli.rs-setup], then `apt install zoxide` |
> | openSUSE Tumbleweed | [openSUSE Factory] | `zypper install zoxide` | > | Manjaro | | `pacman -S zoxide` |
> | ~Parrot OS~[^1] | | ~`apt install zoxide`~ | > | openSUSE Tumbleweed | [openSUSE Factory] | `zypper install zoxide` |
> | ~Raspbian 11+~[^1] | ~[Raspbian Packages]~ | ~`apt install zoxide`~ | > | ~Parrot OS~[^1] | | ~`apt install zoxide`~ |
> | RHEL 8+ | | `dnf install zoxide` | > | ~Raspbian 11+~[^1] | ~[Raspbian Packages]~ | ~`apt install zoxide`~ |
> | Rhino Linux | [Pacstall Packages] | `pacstall -I zoxide-deb` | > | RHEL 8+ | | `dnf install zoxide` |
> | Rocky Linux | | `dnf install zoxide` | > | Rhino Linux | [Pacstall Packages] | `pacstall -I zoxide-deb` |
> | Slackware 15.0+ | [SlackBuilds] | [Instructions][slackbuilds-howto] | > | Rocky Linux | | `dnf install zoxide` |
> | Solus | [Solus Packages] | `eopkg install zoxide` | > | Slackware 15.0+ | [SlackBuilds] | [Instructions][slackbuilds-howto] |
> | ~Ubuntu 21.04+~[^1] | ~[Ubuntu Packages]~ | ~`apt install zoxide`~ | > | Solus | [Solus Packages] | `eopkg install zoxide` |
> | Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` | > | Ubuntu | [apt.cli.rs] (unofficial) | [Setup the repository][apt.cli.rs-setup], then `apt install zoxide` |
> | Void Linux | [Void Linux Packages] | `xbps-install -S zoxide` |
</details> </details>
@ -487,7 +488,7 @@ Environment variables[^2] can be used for configuration. They must be set before
| [zsh-autocomplete] | Realtime completions for zsh | Natively supported | | [zsh-autocomplete] | Realtime completions for zsh | Natively supported |
[^1]: [^1]:
Debian / Ubuntu derivatives update their packages very slowly. If you're Debian and its derivatives update their packages very slowly. If you're
using one of these distributions, consider using the install script instead. using one of these distributions, consider using the install script instead.
[^2]: [^2]:
@ -500,6 +501,8 @@ Environment variables[^2] can be used for configuration. They must be set before
[algorithm-aging]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#aging [algorithm-aging]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#aging
[algorithm-matching]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#matching [algorithm-matching]: https://github.com/ajeetdsouza/zoxide/wiki/Algorithm#matching
[alpine linux packages]: https://pkgs.alpinelinux.org/packages?name=zoxide [alpine linux packages]: https://pkgs.alpinelinux.org/packages?name=zoxide
[apt.cli.rs]: https://apt.cli.rs/
[apt.cli.rs-setup]: https://github.com/emmatyping/apt.cli.rs#how-to-add-the-repo
[arch linux extra]: https://archlinux.org/packages/extra/x86_64/zoxide/ [arch linux extra]: https://archlinux.org/packages/extra/x86_64/zoxide/
[asdf]: https://github.com/asdf-vm/asdf [asdf]: https://github.com/asdf-vm/asdf
[builtwithnix-badge]: https://img.shields.io/badge/builtwith-nix-7d81f7?logo=nixos&logoColor=white&style=flat-square [builtwithnix-badge]: https://img.shields.io/badge/builtwith-nix-7d81f7?logo=nixos&logoColor=white&style=flat-square
@ -555,7 +558,6 @@ Environment variables[^2] can be used for configuration. They must be set before
[tmux-session-wizard]: https://github.com/27medkamal/tmux-session-wizard [tmux-session-wizard]: https://github.com/27medkamal/tmux-session-wizard
[tmux-sessionx]: https://github.com/omerxx/tmux-sessionx [tmux-sessionx]: https://github.com/omerxx/tmux-sessionx
[tutorial]: contrib/tutorial.webp [tutorial]: contrib/tutorial.webp
[ubuntu packages]: https://packages.ubuntu.com/jammy/zoxide
[vim]: https://github.com/vim/vim [vim]: https://github.com/vim/vim
[void linux packages]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zoxide [void linux packages]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zoxide
[wiki-env]: https://github.com/ajeetdsouza/zoxide/wiki/HOWTO:-set-environment-variables "HOWTO: set environment variables" [wiki-env]: https://github.com/ajeetdsouza/zoxide/wiki/HOWTO:-set-environment-variables "HOWTO: set environment variables"

View File

@ -6,6 +6,7 @@ use std::{env, io};
use clap::CommandFactory as _; use clap::CommandFactory as _;
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh}; use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
use clap_complete_fig::Fig; use clap_complete_fig::Fig;
use clap_complete_nushell::Nushell;
use cmd::Cmd; use cmd::Cmd;
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
@ -27,6 +28,7 @@ fn generate_completions() -> io::Result<()> {
clap_complete::generate_to(Elvish, cmd, BIN_NAME, OUT_DIR)?; clap_complete::generate_to(Elvish, cmd, BIN_NAME, OUT_DIR)?;
clap_complete::generate_to(Fig, cmd, BIN_NAME, OUT_DIR)?; clap_complete::generate_to(Fig, cmd, BIN_NAME, OUT_DIR)?;
clap_complete::generate_to(Fish, cmd, BIN_NAME, OUT_DIR)?; clap_complete::generate_to(Fish, cmd, BIN_NAME, OUT_DIR)?;
clap_complete::generate_to(Nushell, cmd, BIN_NAME, OUT_DIR)?;
clap_complete::generate_to(PowerShell, cmd, BIN_NAME, OUT_DIR)?; clap_complete::generate_to(PowerShell, cmd, BIN_NAME, OUT_DIR)?;
clap_complete::generate_to(Zsh, cmd, BIN_NAME, OUT_DIR)?; clap_complete::generate_to(Zsh, cmd, BIN_NAME, OUT_DIR)?;

View File

@ -30,8 +30,8 @@ _zoxide() {
case $line[1] in case $line[1] in
(add) (add)
_arguments "${_arguments_options[@]}" : \ _arguments "${_arguments_options[@]}" : \
'-s+[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE: ' \ '-s+[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE:_default' \
'--score=[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE: ' \ '--score=[The rank to increment the entry if it exists or initialize it with if it doesn'\''t]:SCORE:_default' \
'-h[Print help]' \ '-h[Print help]' \
'--help[Print help]' \ '--help[Print help]' \
'-V[Print version]' \ '-V[Print version]' \
@ -61,7 +61,7 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \ '--help[Print help]' \
'-V[Print version]' \ '-V[Print version]' \
'--version[Print version]' \ '--version[Print version]' \
':path:' \ ':path:_default' \
&& ret=0 && ret=0
;; ;;
(delete) (delete)
@ -70,7 +70,7 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \ '--help[Print help]' \
'-V[Print version]' \ '-V[Print version]' \
'--version[Print version]' \ '--version[Print version]' \
':path:' \ ':path:_default' \
&& ret=0 && ret=0
;; ;;
(increment) (increment)
@ -79,7 +79,7 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \ '--help[Print help]' \
'-V[Print version]' \ '-V[Print version]' \
'--version[Print version]' \ '--version[Print version]' \
':path:' \ ':path:_default' \
&& ret=0 && ret=0
;; ;;
(reload) (reload)
@ -107,7 +107,7 @@ _arguments "${_arguments_options[@]}" : \
;; ;;
(init) (init)
_arguments "${_arguments_options[@]}" : \ _arguments "${_arguments_options[@]}" : \
'--cmd=[Changes the prefix of the \`z\` and \`zi\` commands]:CMD: ' \ '--cmd=[Changes the prefix of the \`z\` and \`zi\` commands]:CMD:_default' \
'--hook=[Changes how often zoxide increments a directory'\''s score]:HOOK:(none prompt pwd)' \ '--hook=[Changes how often zoxide increments a directory'\''s score]:HOOK:(none prompt pwd)' \
'--no-cmd[Prevents zoxide from defining the \`z\` and \`zi\` commands]' \ '--no-cmd[Prevents zoxide from defining the \`z\` and \`zi\` commands]' \
'-h[Print help]' \ '-h[Print help]' \
@ -132,7 +132,7 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \ '--help[Print help]' \
'-V[Print version]' \ '-V[Print version]' \
'--version[Print version]' \ '--version[Print version]' \
'*::keywords:' \ '*::keywords:_default' \
&& ret=0 && ret=0
;; ;;
(remove) (remove)

View File

@ -1,12 +1,16 @@
_zoxide() { _zoxide() {
local i cur prev opts cmd local i cur prev opts cmd
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
prev="${COMP_WORDS[COMP_CWORD-1]}" cur="$2"
else
cur="${COMP_WORDS[COMP_CWORD]}"
fi
prev="$3"
cmd="" cmd=""
opts="" opts=""
for i in ${COMP_WORDS[@]} for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
do do
case "${cmd},${i}" in case "${cmd},${i}" in
",$1") ",$1")

View File

@ -49,12 +49,15 @@ complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subc
complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from increment" -s V -l version -d 'Print version' complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from increment" -s V -l version -d 'Print version'
complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from reload" -s h -l help -d 'Print help' complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from reload" -s h -l help -d 'Print help'
complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from reload" -s V -l version -d 'Print version' complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and __fish_seen_subcommand_from reload" -s V -l version -d 'Print version'
complete -c zoxide -n "__fish_zoxide_using_subcommand import" -l from -d 'Application to import from' -r -f -a "{autojump\t'',z\t''}" complete -c zoxide -n "__fish_zoxide_using_subcommand import" -l from -d 'Application to import from' -r -f -a "autojump\t''
z\t''"
complete -c zoxide -n "__fish_zoxide_using_subcommand import" -l merge -d 'Merge into existing database' complete -c zoxide -n "__fish_zoxide_using_subcommand import" -l merge -d 'Merge into existing database'
complete -c zoxide -n "__fish_zoxide_using_subcommand import" -s h -l help -d 'Print help' complete -c zoxide -n "__fish_zoxide_using_subcommand import" -s h -l help -d 'Print help'
complete -c zoxide -n "__fish_zoxide_using_subcommand import" -s V -l version -d 'Print version' complete -c zoxide -n "__fish_zoxide_using_subcommand import" -s V -l version -d 'Print version'
complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l cmd -d 'Changes the prefix of the `z` and `zi` commands' -r complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l cmd -d 'Changes the prefix of the `z` and `zi` commands' -r
complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l hook -d 'Changes how often zoxide increments a directory\'s score' -r -f -a "{none\t'',prompt\t'',pwd\t''}" complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l hook -d 'Changes how often zoxide increments a directory\'s score' -r -f -a "none\t''
prompt\t''
pwd\t''"
complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l no-cmd -d 'Prevents zoxide from defining the `z` and `zi` commands' complete -c zoxide -n "__fish_zoxide_using_subcommand init" -l no-cmd -d 'Prevents zoxide from defining the `z` and `zi` commands'
complete -c zoxide -n "__fish_zoxide_using_subcommand init" -s h -l help -d 'Print help' complete -c zoxide -n "__fish_zoxide_using_subcommand init" -s h -l help -d 'Print help'
complete -c zoxide -n "__fish_zoxide_using_subcommand init" -s V -l version -d 'Print version' complete -c zoxide -n "__fish_zoxide_using_subcommand init" -s V -l version -d 'Print version'

98
contrib/completions/zoxide.nu generated Normal file
View File

@ -0,0 +1,98 @@
module completions {
# A smarter cd command for your terminal
export extern zoxide [
--help(-h) # Print help
--version(-V) # Print version
]
# Add a new directory or increment its rank
export extern "zoxide add" [
...paths: path
--score(-s): string # The rank to increment the entry if it exists or initialize it with if it doesn't
--help(-h) # Print help
--version(-V) # Print version
]
# Edit the database
export extern "zoxide edit" [
--help(-h) # Print help
--version(-V) # Print version
]
export extern "zoxide edit decrement" [
path: string
--help(-h) # Print help
--version(-V) # Print version
]
export extern "zoxide edit delete" [
path: string
--help(-h) # Print help
--version(-V) # Print version
]
export extern "zoxide edit increment" [
path: string
--help(-h) # Print help
--version(-V) # Print version
]
export extern "zoxide edit reload" [
--help(-h) # Print help
--version(-V) # Print version
]
def "nu-complete zoxide import from" [] {
[ "autojump" "z" ]
}
# Import entries from another application
export extern "zoxide import" [
path: path
--from: string@"nu-complete zoxide import from" # Application to import from
--merge # Merge into existing database
--help(-h) # Print help
--version(-V) # Print version
]
def "nu-complete zoxide init shell" [] {
[ "bash" "elvish" "fish" "nushell" "posix" "powershell" "tcsh" "xonsh" "zsh" ]
}
def "nu-complete zoxide init hook" [] {
[ "none" "prompt" "pwd" ]
}
# Generate shell configuration
export extern "zoxide init" [
shell: string@"nu-complete zoxide init shell"
--no-cmd # Prevents zoxide from defining the `z` and `zi` commands
--cmd: string # Changes the prefix of the `z` and `zi` commands
--hook: string@"nu-complete zoxide init hook" # Changes how often zoxide increments a directory's score
--help(-h) # Print help
--version(-V) # Print version
]
# Search for a directory in the database
export extern "zoxide query" [
...keywords: string
--all(-a) # Show unavailable directories
--interactive(-i) # Use interactive selection
--list(-l) # List all matching directories
--score(-s) # Print score with results
--exclude: path # Exclude the current directory
--help(-h) # Print help
--version(-V) # Print version
]
# Remove a directory from the database
export extern "zoxide remove" [
...paths: path
--help(-h) # Print help
--version(-V) # Print version
]
}
export use completions *

View File

@ -1,7 +1,7 @@
use std::io::{self, Write}; use std::io::{self, Write};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use rinja::Template; use askama::Template;
use crate::cmd::{Init, InitShell, Run}; use crate::cmd::{Init, InitShell, Run};
use crate::config; use crate::config;

View File

@ -10,7 +10,7 @@ pub struct Opts<'a> {
macro_rules! make_template { macro_rules! make_template {
($name:ident, $path:expr) => { ($name:ident, $path:expr) => {
#[derive(::std::fmt::Debug, ::rinja::Template)] #[derive(::std::fmt::Debug, ::askama::Template)]
#[template(path = $path)] #[template(path = $path)]
pub struct $name<'a>(pub &'a self::Opts<'a>); pub struct $name<'a>(pub &'a self::Opts<'a>);
@ -36,8 +36,8 @@ make_template!(Zsh, "zsh.txt");
#[cfg(feature = "nix-dev")] #[cfg(feature = "nix-dev")]
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use askama::Template;
use assert_cmd::Command; use assert_cmd::Command;
use rinja::Template;
use rstest::rstest; use rstest::rstest;
use rstest_reuse::{apply, template}; use rstest_reuse::{apply, template};

View File

@ -169,13 +169,12 @@ pub fn write(path: impl AsRef<Path>, contents: impl AsRef<[u8]>) -> Result<()> {
#[cfg(unix)] #[cfg(unix)]
if let Ok(metadata) = path.metadata() { if let Ok(metadata) = path.metadata() {
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::os::unix::io::AsRawFd;
use nix::unistd::{self, Gid, Uid}; use nix::unistd::{self, Gid, Uid};
let uid = Uid::from_raw(metadata.uid()); let uid = Uid::from_raw(metadata.uid());
let gid = Gid::from_raw(metadata.gid()); let gid = Gid::from_raw(metadata.gid());
_ = unistd::fchown(tmp_file.as_raw_fd(), Some(uid), Some(gid)); _ = unistd::fchown(&tmp_file, Some(uid), Some(gid));
} }
// Close and rename the tmpfile. // Close and rename the tmpfile.

View File

@ -26,7 +26,7 @@ export-env {
if not $__zoxide_hooked { if not $__zoxide_hooked {
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append { $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {
__zoxide_hook: true, __zoxide_hook: true,
code: {|| zoxide add -- $env.PWD} code: {|| ^zoxide add -- $env.PWD}
}) })
} }
{%- else if hook == InitHook::Pwd %} {%- else if hook == InitHook::Pwd %}
@ -43,7 +43,7 @@ export-env {
if not $__zoxide_hooked { if not $__zoxide_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
__zoxide_hook: true, __zoxide_hook: true,
code: {|_, dir| zoxide add -- $dir} code: {|_, dir| ^zoxide add -- $dir}
}) })
} }
{%- endif %} {%- endif %}
@ -60,7 +60,7 @@ module zoxide-commands {
def "nu-complete zoxide path" [context: string] { def "nu-complete zoxide path" [context: string] {
let parts = $context | str trim | split row " " | skip 1 | each { str downcase } let parts = $context | str trim | split row " " | skip 1 | each { str downcase }
let completions = ( let completions = (
zoxide query --list --exclude $env.PWD -- ...$parts ^zoxide query --list --exclude $env.PWD -- ...$parts
| lines | lines
| each { |dir| | each { |dir|
if ($parts | length) <= 1 { if ($parts | length) <= 1 {
@ -93,7 +93,7 @@ module zoxide-commands {
[ '-' ] => {'-'}, [ '-' ] => {'-'},
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
_ => { _ => {
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
} }
} }
cd $path cd $path
@ -104,7 +104,7 @@ module zoxide-commands {
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
export def --env --wrapped __zoxide_zi [...rest:string@"nu-complete zoxide path"] { export def --env --wrapped __zoxide_zi [...rest:string@"nu-complete zoxide path"] {
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")' cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %} {%- if echo %}
echo $env.PWD echo $env.PWD
{%- endif %} {%- endif %}