From acc905917724079c114e092fdd4ef04b9c7ba779 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 13 Apr 2021 01:57:36 +0530 Subject: [PATCH] Fix cd - on fish (#179) --- CHANGELOG.md | 6 ++++++ README.md | 17 +++++++++-------- src/cmd/init.rs | 2 +- src/cmd/mod.rs | 8 +++++++- src/cmd/query.rs | 2 +- src/cmd/remove.rs | 2 +- templates/fish.txt | 9 +++++---- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f36a58..8187b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- `cd -` on fish shells. + ## [0.6.0] - 2021-04-09 ### Added diff --git a/README.md b/README.md index cae87fe..9209d96 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,15 @@ frequently, and uses a ranking algorithm to navigate to the best match. ## Examples ```sh -z foo # cd into highest ranked directory matching foo -z foo bar # cd into highest ranked directory matching foo and bar +z foo # cd into highest ranked directory matching foo +z foo bar # cd into highest ranked directory matching foo and bar -z ~/foo # z also works like a regular cd command -z foo/ # cd into relative path -z .. # cd one level up -z - # cd into previous directory +z ~/foo # z also works like a regular cd command +z foo/ # cd into relative path +z .. # cd one level up +z - # cd into previous directory -zi foo # cd with interactive selection (using fzf) +zi foo # cd with interactive selection (using fzf) ``` Read more about the matching algorithm [here][algorithm-matching]. @@ -174,7 +174,8 @@ eval "$(zoxide init zsh)" #### Any POSIX shell -Add the following line to your configuration file: +Add the following line to your configuration file (usually +`~/.config/nu/config.toml`): ```sh eval "$(zoxide init posix --hook prompt)" diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 23f3406..f6f43d1 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -10,7 +10,7 @@ use once_cell::sync::OnceCell; use std::io::{self, Write}; -/// Generates shell configuration +/// Generate shell configuration #[derive(Clap, Debug)] #[clap(after_help(env_help()))] pub struct Init { diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index b8dbaae..7be662b 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -18,7 +18,13 @@ pub trait Cmd { } #[derive(Debug, Clap)] -#[clap(about, author, global_setting(AppSettings::GlobalVersion), global_setting(AppSettings::VersionlessSubcommands), version = env!("ZOXIDE_VERSION"))] +#[clap( + about, + author, + global_setting(AppSettings::DisableHelpSubcommand), + global_setting(AppSettings::GlobalVersion), + global_setting(AppSettings::VersionlessSubcommands), + version = env!("ZOXIDE_VERSION"))] pub enum App { Add(Add), Import(Import), diff --git a/src/cmd/query.rs b/src/cmd/query.rs index fa2a8d4..bd7cb12 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -10,7 +10,7 @@ use clap::Clap; use std::io::{self, Write}; -/// Searches for a directory +/// Search for a directory in the database #[derive(Clap, Debug)] pub struct Query { keywords: Vec, diff --git a/src/cmd/remove.rs b/src/cmd/remove.rs index 5021868..8a84d9a 100644 --- a/src/cmd/remove.rs +++ b/src/cmd/remove.rs @@ -10,7 +10,7 @@ use clap::Clap; use std::io::Write; -/// Removes a directory +/// Remove a directory from the database #[derive(Clap, Debug)] pub struct Remove { #[clap(conflicts_with = "path", long, short, value_name = "keywords")] diff --git a/templates/fish.txt b/templates/fish.txt index 5b31019..c970983 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -16,7 +16,10 @@ end # cd + custom logic based on the value of _ZO_ECHO. function __zoxide_cd - builtin cd $argv +{#- We can't use `builtin cd` over here, because fish wraps its builtin cd with + a function that adds extra features (such as `cd -`). Using the builtin + would make those features stop working. #} + cd $argv {%- if echo %} and __zoxide_pwd {%- endif %} @@ -52,9 +55,7 @@ function __zoxide_z set argc (count $argv) if test $argc -eq 0 __zoxide_cd $HOME - else if begin - test $argc -eq 1; and test $argv[1] = - - end + else if test "$argv" = - __zoxide_cd - else if begin test $argc -eq 1; and test -d $argv[1]