Merge branch 'ajeetdsouza:main' into main
This commit is contained in:
commit
ac92a2f080
|
@ -36,17 +36,17 @@ jobs:
|
|||
components: rustfmt
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
- uses: cachix/install-nix-action@v30
|
||||
- uses: cachix/install-nix-action@v31
|
||||
if: ${{ matrix.os != 'windows-latest' }}
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
- uses: cachix/cachix-action@v15
|
||||
- uses: cachix/cachix-action@v16
|
||||
if: ${{ matrix.os != 'windows-latest' && env.CACHIX_AUTH_TOKEN != '' }}
|
||||
with:
|
||||
authToken: ${{ env.CACHIX_AUTH_TOKEN }}
|
||||
name: zoxide
|
||||
- name: Setup cache
|
||||
uses: Swatinem/rust-cache@v2.7.7
|
||||
uses: Swatinem/rust-cache@v2.7.8
|
||||
with:
|
||||
key: ${{ matrix.os }}
|
||||
- name: Install just
|
||||
|
|
|
@ -59,7 +59,7 @@ jobs:
|
|||
override: true
|
||||
target: ${{ matrix.target }}
|
||||
- name: Setup cache
|
||||
uses: Swatinem/rust-cache@v2.7.7
|
||||
uses: Swatinem/rust-cache@v2.7.8
|
||||
with:
|
||||
key: ${{ matrix.target }}
|
||||
- name: Install cross
|
||||
|
|
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -7,6 +7,27 @@ 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
|
||||
|
||||
### Added
|
||||
|
||||
- Support for Tcsh.
|
||||
- Added `--score` flag to `zoxide add`.
|
||||
- POSIX: add doctor to diagnose common issues.
|
||||
|
||||
### Changed
|
||||
|
||||
- Bash: zoxide will now rewrite the prompt when using Space-Tab completions.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bash: doctor now handles `PROMPT_COMMAND` being an array.
|
||||
- Bash: doctor now handles Visual Studio Code's shell integration.
|
||||
- Bash: completions now work with `ble.sh`.
|
||||
- Nushell: stop ignoring symlinks when `cd`-ing into a directory.
|
||||
- Fzf: updated minimum supported version to v0.51.0.
|
||||
- PowerShell: avoid setting `$error` when defining `__zoxide_hooked`.
|
||||
|
||||
## [0.9.7] - 2025-02-10
|
||||
|
||||
### Added
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
authors = ["Ajeet D'Souza <98ajeet@gmail.com>"]
|
||||
categories = ["command-line-utilities", "filesystem"]
|
||||
description = "A smarter cd command for your terminal"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
homepage = "https://github.com/ajeetdsouza/zoxide"
|
||||
keywords = ["cli", "filesystem", "shell", "tool", "utility"]
|
||||
license = "MIT"
|
||||
name = "zoxide"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/ajeetdsouza/zoxide"
|
||||
rust-version = "1.74.1"
|
||||
rust-version = "1.85.0"
|
||||
version = "0.9.7"
|
||||
|
||||
[badges]
|
||||
|
|
28
README.md
28
README.md
|
@ -13,7 +13,7 @@
|
|||
|
||||
<div><img src="contrib/warp.png" width="230" alt="Warp" /></div>
|
||||
<div><sup><b>Warp, the intelligent terminal</b></sup></div>
|
||||
<div><sup>Available for MacOS and Linux</sup></div>
|
||||
<div><sup>Available for MacOS, Linux, and Windows</sup></div>
|
||||
<div><sup>
|
||||
Visit
|
||||
<a href="https://www.warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=zoxide_20231001"><u>warp.dev</u></a>
|
||||
|
@ -280,6 +280,18 @@ zoxide can be installed in 4 easy steps:
|
|||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Tcsh</summary>
|
||||
|
||||
> Add this to the <ins>**end**</ins> of your config file (usually `~/.tcshrc`):
|
||||
>
|
||||
> ```sh
|
||||
> zoxide init tcsh > ~/.zoxide.tcsh
|
||||
> source ~/.zoxide.tcsh
|
||||
> ```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Xonsh</summary>
|
||||
|
||||
|
@ -323,7 +335,7 @@ zoxide can be installed in 4 easy steps:
|
|||
interactive selection. It can be installed from [here][fzf-installation].
|
||||
|
||||
> **Note**
|
||||
> zoxide only supports fzf v0.33.0 and above.
|
||||
> The minimum supported fzf version is v0.51.0.
|
||||
|
||||
4. **Import your data** <sup>(optional)</sup>
|
||||
|
||||
|
@ -461,14 +473,17 @@ Environment variables[^2] can be used for configuration. They must be set before
|
|||
| [lf] | File manager | See the [wiki][lf-wiki] |
|
||||
| [nnn] | File manager | [nnn-autojump] |
|
||||
| [ranger] | File manager | [ranger-zoxide] |
|
||||
| [rfm] | File manager | Natively supported |
|
||||
| [sesh] | `tmux` session manager | Natively supported |
|
||||
| [telescope.nvim] | Fuzzy finder for Neovim | [telescope-zoxide] |
|
||||
| [t] | `tmux` session manager | Natively supported |
|
||||
| [tmux-session-wizard] | `tmux` session manager | Natively supported |
|
||||
| [tmux-sessionx] | `tmux` session manager | Natively supported |
|
||||
| [vim] / [neovim] | Text editor | [zoxide.vim] |
|
||||
| [xplr] | File manager | [zoxide.xplr] |
|
||||
| [xxh] | Transports shell configuration over SSH | [xxh-plugin-prerun-zoxide] |
|
||||
| [yazi] | File manager | Natively supported |
|
||||
| [zabb] | Finds the shortest possible query for a path | Natively supported |
|
||||
| [zesh] | `zellij` session manager | Natively supported |
|
||||
| [zsh-autocomplete] | Realtime completions for zsh | Natively supported |
|
||||
|
||||
[^1]:
|
||||
|
@ -518,7 +533,7 @@ Environment variables[^2] can be used for configuration. They must be set before
|
|||
[linuxbrew]: https://formulae.brew.sh/formula-linux/zoxide
|
||||
[macports]: https://ports.macports.org/port/zoxide/summary
|
||||
[neovim]: https://github.com/neovim/neovim
|
||||
[nixpkgs]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/zoxide/default.nix
|
||||
[nixpkgs]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/zo/zoxide/package.nix
|
||||
[nnn-autojump]: https://github.com/jarun/nnn/blob/master/plugins/autojump
|
||||
[nnn]: https://github.com/jarun/nnn
|
||||
[opensuse factory]: https://build.opensuse.org/package/show/openSUSE:Factory/zoxide
|
||||
|
@ -528,15 +543,17 @@ Environment variables[^2] can be used for configuration. They must be set before
|
|||
[ranger]: https://github.com/ranger/ranger
|
||||
[raspbian packages]: https://archive.raspbian.org/raspbian/pool/main/r/rust-zoxide/
|
||||
[releases]: https://github.com/ajeetdsouza/zoxide/releases
|
||||
[rfm]: https://github.com/dsxmachina/rfm
|
||||
[scoop]: https://github.com/ScoopInstaller/Main/tree/master/bucket/zoxide.json
|
||||
[sesh]: https://github.com/joshmedeski/sesh
|
||||
[slackbuilds]: https://slackbuilds.org/repository/15.0/system/zoxide/
|
||||
[slackbuilds-howto]: https://slackbuilds.org/howto/
|
||||
[solus packages]: https://github.com/getsolus/packages/tree/main/packages/z/zoxide/
|
||||
[t]: https://github.com/joshmedeski/t-smart-tmux-session-manager
|
||||
[telescope-zoxide]: https://github.com/jvgrootveld/telescope-zoxide
|
||||
[telescope.nvim]: https://github.com/nvim-telescope/telescope.nvim
|
||||
[termux]: https://github.com/termux/termux-packages/tree/master/packages/zoxide
|
||||
[tmux-session-wizard]: https://github.com/27medkamal/tmux-session-wizard
|
||||
[tmux-sessionx]: https://github.com/omerxx/tmux-sessionx
|
||||
[tutorial]: contrib/tutorial.webp
|
||||
[ubuntu packages]: https://packages.ubuntu.com/jammy/zoxide
|
||||
[vim]: https://github.com/vim/vim
|
||||
|
@ -547,6 +564,7 @@ Environment variables[^2] can be used for configuration. They must be set before
|
|||
[xxh]: https://github.com/xxh/xxh
|
||||
[yazi]: https://github.com/sxyazi/yazi
|
||||
[zabb]: https://github.com/Mellbourn/zabb
|
||||
[zesh]: https://github.com/roberte777/zesh
|
||||
[zoxide.el]: https://gitlab.com/Vonfry/zoxide.el
|
||||
[zoxide.vim]: https://github.com/nanotee/zoxide.vim
|
||||
[zoxide.xplr]: https://github.com/sayanarijit/zoxide.xplr
|
||||
|
|
|
@ -30,6 +30,8 @@ _zoxide() {
|
|||
case $line[1] in
|
||||
(add)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'-s+[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: ' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
|
@ -112,7 +114,7 @@ _arguments "${_arguments_options[@]}" : \
|
|||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
':shell:(bash elvish fish nushell posix powershell xonsh zsh)' \
|
||||
':shell:(bash elvish fish nushell posix powershell tcsh xonsh zsh)' \
|
||||
&& ret=0
|
||||
;;
|
||||
(query)
|
||||
|
|
|
@ -34,6 +34,8 @@ Register-ArgumentCompleter -Native -CommandName 'zoxide' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'zoxide;add' {
|
||||
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'The rank to increment the entry if it exists or initialize it with if it doesn''t')
|
||||
[CompletionResult]::new('--score', '--score', [CompletionResultType]::ParameterName, 'The rank to increment the entry if it exists or initialize it with if it doesn''t')
|
||||
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||
|
|
|
@ -63,12 +63,20 @@ _zoxide() {
|
|||
return 0
|
||||
;;
|
||||
zoxide__add)
|
||||
opts="-h -V --help --version <PATHS>..."
|
||||
opts="-s -h -V --score --help --version <PATHS>..."
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
--score)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-s)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
|
@ -165,7 +173,7 @@ _zoxide() {
|
|||
return 0
|
||||
;;
|
||||
zoxide__init)
|
||||
opts="-h -V --no-cmd --cmd --hook --help --version bash elvish fish nushell posix powershell xonsh zsh"
|
||||
opts="-h -V --no-cmd --cmd --hook --help --version bash elvish fish nushell posix powershell tcsh xonsh zsh"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
|
|
@ -30,6 +30,8 @@ set edit:completion:arg-completer[zoxide] = {|@words|
|
|||
cand remove 'Remove a directory from the database'
|
||||
}
|
||||
&'zoxide;add'= {
|
||||
cand -s 'The rank to increment the entry if it exists or initialize it with if it doesn''t'
|
||||
cand --score 'The rank to increment the entry if it exists or initialize it with if it doesn''t'
|
||||
cand -h 'Print help'
|
||||
cand --help 'Print help'
|
||||
cand -V 'Print version'
|
||||
|
|
|
@ -32,6 +32,7 @@ complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "import" -d 'Import en
|
|||
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "init" -d 'Generate shell configuration'
|
||||
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "query" -d 'Search for a directory in the database'
|
||||
complete -c zoxide -n "__fish_zoxide_needs_command" -f -a "remove" -d 'Remove a directory from the database'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s s -l score -d 'The rank to increment the entry if it exists or initialize it with if it doesn\'t' -r
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s h -l help -d 'Print help'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand add" -s V -l version -d 'Print version'
|
||||
complete -c zoxide -n "__fish_zoxide_using_subcommand edit; and not __fish_seen_subcommand_from decrement delete increment reload" -s h -l help -d 'Print help'
|
||||
|
|
|
@ -6,6 +6,15 @@ const completion: Fig.Spec = {
|
|||
name: "add",
|
||||
description: "Add a new directory or increment its rank",
|
||||
options: [
|
||||
{
|
||||
name: ["-s", "--score"],
|
||||
description: "The rank to increment the entry if it exists or initialize it with if it doesn't",
|
||||
isRepeatable: true,
|
||||
args: {
|
||||
name: "score",
|
||||
isOptional: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["-h", "--help"],
|
||||
description: "Print help",
|
||||
|
@ -185,6 +194,7 @@ const completion: Fig.Spec = {
|
|||
"nushell",
|
||||
"posix",
|
||||
"powershell",
|
||||
"tcsh",
|
||||
"xonsh",
|
||||
"zsh",
|
||||
],
|
||||
|
|
|
@ -55,6 +55,14 @@ $profile\fR in PowerShell):
|
|||
\fBInvoke-Expression (& { (zoxide init powershell | Out-String) })\fR
|
||||
.fi
|
||||
.TP
|
||||
.B tcsh
|
||||
Add this to the \fBend\fR of your config file (usually \fB~/.tcshrc\fR):
|
||||
.sp
|
||||
.nf
|
||||
\fBzoxide init tcsh > ~/.zoxide.tcsh\fR
|
||||
\fBsource ~/.zoxide.tcsh\fR
|
||||
.fi
|
||||
.TP
|
||||
.B xonsh
|
||||
Add this to the \fBend\fR of your config file (usually \fB~/.xonshrc\fR):
|
||||
.sp
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
let
|
||||
pkgs = import (builtins.fetchTarball
|
||||
"https://github.com/NixOS/nixpkgs/archive/056faf24027e12f0ba6edebe299ed136e030d29a.tar.gz") {
|
||||
"https://github.com/NixOS/nixpkgs/archive/ec9ef366451af88284d7dfd18ee017b7e86a0710.tar.gz") {
|
||||
overlays = [ rust ];
|
||||
};
|
||||
rust = import (builtins.fetchTarball
|
||||
"https://github.com/oxalica/rust-overlay/archive/f61820fa2c3844d6940cce269a6afdec30aa2e6c.tar.gz");
|
||||
"https://github.com/oxalica/rust-overlay/archive/026e8fedefd6b167d92ed04b195c658d95ffc7a5.tar.gz");
|
||||
|
||||
rust-nightly =
|
||||
pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal);
|
||||
|
@ -27,6 +27,7 @@ in pkgs.mkShell {
|
|||
pkgs.ksh
|
||||
pkgs.nushell
|
||||
pkgs.powershell
|
||||
pkgs.tcsh
|
||||
pkgs.xonsh
|
||||
pkgs.zsh
|
||||
|
||||
|
|
|
@ -33,7 +33,9 @@ impl Run for Add {
|
|||
if !Path::new(path).is_dir() {
|
||||
bail!("not a directory: {path}");
|
||||
}
|
||||
db.add_update(path, 1.0, now);
|
||||
|
||||
let by = self.score.unwrap_or(1.0);
|
||||
db.add_update(path, by, now);
|
||||
}
|
||||
|
||||
if db.dirty() {
|
||||
|
|
|
@ -58,6 +58,11 @@ pub enum Cmd {
|
|||
pub struct Add {
|
||||
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
|
||||
pub paths: Vec<PathBuf>,
|
||||
|
||||
/// The rank to increment the entry if it exists or initialize it with if it
|
||||
/// doesn't
|
||||
#[clap(short, long)]
|
||||
pub score: Option<f64>,
|
||||
}
|
||||
|
||||
/// Edit the database
|
||||
|
@ -148,6 +153,7 @@ pub enum InitShell {
|
|||
#[clap(alias = "ksh")]
|
||||
Posix,
|
||||
Powershell,
|
||||
Tcsh,
|
||||
Xonsh,
|
||||
Zsh,
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use rinja::Template;
|
|||
use crate::cmd::{Init, InitShell, Run};
|
||||
use crate::config;
|
||||
use crate::error::BrokenPipeHandler;
|
||||
use crate::shell::{Bash, Elvish, Fish, Nushell, Opts, Posix, Powershell, Xonsh, Zsh};
|
||||
use crate::shell::{Bash, Elvish, Fish, Nushell, Opts, Posix, Powershell, Tcsh, Xonsh, Zsh};
|
||||
|
||||
impl Run for Init {
|
||||
fn run(&self) -> Result<()> {
|
||||
|
@ -22,6 +22,7 @@ impl Run for Init {
|
|||
InitShell::Nushell => Nushell(opts).render(),
|
||||
InitShell::Posix => Posix(opts).render(),
|
||||
InitShell::Powershell => Powershell(opts).render(),
|
||||
InitShell::Tcsh => Tcsh(opts).render(),
|
||||
InitShell::Xonsh => Xonsh(opts).render(),
|
||||
InitShell::Zsh => Zsh(opts).render(),
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use crate::error::SilentExit;
|
|||
|
||||
pub fn main() -> ExitCode {
|
||||
// Forcibly disable backtraces.
|
||||
env::remove_var("RUST_LIB_BACKTRACE");
|
||||
env::remove_var("RUST_BACKTRACE");
|
||||
unsafe { env::remove_var("RUST_LIB_BACKTRACE") };
|
||||
unsafe { env::remove_var("RUST_BACKTRACE") };
|
||||
|
||||
match Cmd::parse().run() {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
|
|
15
src/shell.rs
15
src/shell.rs
|
@ -29,6 +29,7 @@ make_template!(Fish, "fish.txt");
|
|||
make_template!(Nushell, "nushell.txt");
|
||||
make_template!(Posix, "posix.txt");
|
||||
make_template!(Powershell, "powershell.txt");
|
||||
make_template!(Tcsh, "tcsh.txt");
|
||||
make_template!(Xonsh, "xonsh.txt");
|
||||
make_template!(Zsh, "zsh.txt");
|
||||
|
||||
|
@ -248,6 +249,20 @@ mod tests {
|
|||
.stderr("");
|
||||
}
|
||||
|
||||
#[apply(opts)]
|
||||
fn tcsh_tcsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Tcsh(&opts).render().unwrap();
|
||||
|
||||
Command::new("tcsh")
|
||||
.args(["-e", "-f", "-s"])
|
||||
.write_stdin(source)
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[apply(opts)]
|
||||
fn xonsh_black(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
|
|
|
@ -179,6 +179,12 @@ pub fn write(path: impl AsRef<Path>, contents: impl AsRef<[u8]>) -> Result<()> {
|
|||
}
|
||||
|
||||
// Close and rename the tmpfile.
|
||||
// In some cases, errors from the last write() are reported only on close().
|
||||
// Rust ignores errors from close(), since it occurs inside `Drop`. To
|
||||
// catch these errors, we manually call `File::sync_all()` first.
|
||||
tmp_file
|
||||
.sync_all()
|
||||
.with_context(|| format!("could not sync writes to file: {}", tmp_path.display()))?;
|
||||
mem::drop(tmp_file);
|
||||
rename(&tmp_path, path)
|
||||
})();
|
||||
|
|
|
@ -66,8 +66,11 @@ function __zoxide_doctor() {
|
|||
return 0
|
||||
|
||||
{%- else %}
|
||||
[[ ${_ZO_DOCTOR:-1} -ne 0 ]] || return 0
|
||||
[[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]] || return 0
|
||||
[[ ${_ZO_DOCTOR:-1} -eq 0 ]] && return 0
|
||||
# shellcheck disable=SC2199
|
||||
[[ ${PROMPT_COMMAND[@]:-} == *'__zoxide_hook'* ]] && return 0
|
||||
# shellcheck disable=SC2199
|
||||
[[ ${__vsc_original_prompt_command[@]:-} == *'__zoxide_hook'* ]] && return 0
|
||||
|
||||
_ZO_DOCTOR=0
|
||||
\builtin printf '%s\n' \
|
||||
|
@ -144,8 +147,11 @@ function {{cmd}}i() {
|
|||
# - Completions don't work on `dumb` terminals.
|
||||
if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VERSINFO[0]:-0} -ge 5 ]] &&
|
||||
[[ :"${SHELLOPTS}": =~ :(vi|emacs): && ${TERM} != 'dumb' ]]; then
|
||||
# Use `printf '\e[5n'` to redraw line after fzf closes.
|
||||
\builtin bind '"\e[0n": redraw-current-line' &>/dev/null
|
||||
|
||||
function __zoxide_z_complete_helper() {
|
||||
READLINE_LINE="{{ cmd }} ${__zoxide_result@Q}"
|
||||
READLINE_POINT={{ "${#READLINE_LINE}" }}
|
||||
}
|
||||
|
||||
function __zoxide_z_complete() {
|
||||
# Only show completions when the cursor is at the end of the line.
|
||||
|
@ -157,12 +163,20 @@ if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VER
|
|||
\builtin compgen -A directory -- "${COMP_WORDS[-1]}" || \builtin true
|
||||
)
|
||||
# If there is a space after the last word, use interactive selection.
|
||||
elif [[ -z ${COMP_WORDS[-1]} ]] && [[ ${COMP_WORDS[-2]} != "${__zoxide_z_prefix}"?* ]]; then
|
||||
\builtin local result
|
||||
elif [[ -z ${COMP_WORDS[-1]} ]]; then
|
||||
# shellcheck disable=SC2312
|
||||
result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" &&
|
||||
COMPREPLY=("${__zoxide_z_prefix}${result}/")
|
||||
\builtin printf '\e[5n'
|
||||
__zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" && {
|
||||
# In case the terminal does not respond to \e[5n or another
|
||||
# mechanism steals the response, it is still worth completing
|
||||
# the directory in the command line.
|
||||
COMPREPLY=("${__zoxide_z_prefix}${__zoxide_result}/")
|
||||
|
||||
# Note: We here call "bind" without prefixing "\builtin" to be
|
||||
# compatible with frameworks like ble.sh, which emulates Bash's
|
||||
# builtin "bind".
|
||||
bind -x '"\e[0n": __zoxide_z_complete_helper'
|
||||
\builtin printf '\e[5n' >/dev/tty
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ def --env --wrapped __zoxide_z [...rest: string] {
|
|||
let path = match $rest {
|
||||
[] => {'~'},
|
||||
[ '-' ] => {'-'},
|
||||
[ $arg ] if ($arg | path type) == 'dir' => {$arg}
|
||||
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
|
||||
_ => {
|
||||
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
||||
}
|
||||
|
|
|
@ -43,6 +43,30 @@ if [ "${PS1:=}" = "${PS1#*\$(__zoxide_hook)}" ]; then
|
|||
PS1="${PS1}\$(__zoxide_hook)"
|
||||
fi
|
||||
|
||||
# Report common issues.
|
||||
__zoxide_doctor() {
|
||||
{%- if hook != InitHook::Prompt %}
|
||||
return 0
|
||||
{%- else %}
|
||||
[ "${_ZO_DOCTOR:-1}" -eq 0 ] && return 0
|
||||
case "${PS1:-}" in
|
||||
*__zoxide_hook*) return 0 ;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
_ZO_DOCTOR=0
|
||||
\command printf '%s\n' \
|
||||
'zoxide: detected a possible configuration issue.' \
|
||||
'Please ensure that zoxide is initialized right at the end of your shell configuration file.' \
|
||||
'' \
|
||||
'If the issue persists, consider filing an issue at:' \
|
||||
'https://github.com/ajeetdsouza/zoxide/issues' \
|
||||
'' \
|
||||
'Disable this message by setting _ZO_DOCTOR=0.' \
|
||||
'' >&2
|
||||
{%- endif %}
|
||||
}
|
||||
|
||||
{%- when InitHook::Pwd -%}
|
||||
\command printf "%s\n%s\n" \
|
||||
"zoxide: PWD hooks are not supported on POSIX shells." \
|
||||
|
@ -56,6 +80,8 @@ fi
|
|||
|
||||
# Jump to a directory using only keywords.
|
||||
__zoxide_z() {
|
||||
__zoxide_doctor
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
__zoxide_cd ~
|
||||
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
|
||||
|
@ -76,6 +102,7 @@ __zoxide_z() {
|
|||
|
||||
# Jump to a directory using interactive search.
|
||||
__zoxide_zi() {
|
||||
__zoxide_doctor
|
||||
__zoxide_result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ function global:__zoxide_hook {
|
|||
{%- endif %}
|
||||
|
||||
# Initialize hook.
|
||||
$global:__zoxide_hooked = (Get-Variable __zoxide_hooked -ErrorAction SilentlyContinue -ValueOnly)
|
||||
$global:__zoxide_hooked = (Get-Variable __zoxide_hooked -ErrorAction Ignore -ValueOnly)
|
||||
if ($global:__zoxide_hooked -ne 1) {
|
||||
$global:__zoxide_hooked = 1
|
||||
$global:__zoxide_prompt_old = $function:prompt
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
{%- let section = "# =============================================================================\n#" -%}
|
||||
{%- let not_configured = "# -- not configured --" -%}
|
||||
|
||||
{%- let pwd_cmd -%}
|
||||
{%- if resolve_symlinks -%}
|
||||
{%- let pwd_cmd = "pwd -P" -%}
|
||||
{%- else -%}
|
||||
{%- let pwd_cmd = "pwd -L" -%}
|
||||
{%- endif -%}
|
||||
|
||||
{{ section }}
|
||||
# Hook configuration for zoxide.
|
||||
#
|
||||
{%- if hook != InitHook::None %}
|
||||
|
||||
# Hook to add new entries to the database.
|
||||
{%- if hook == InitHook::Prompt %}
|
||||
alias __zoxide_hook 'zoxide add -- "`{{ pwd_cmd }}`"'
|
||||
|
||||
{%- else if hook == InitHook::Pwd %}
|
||||
set __zoxide_pwd_old = `{{ pwd_cmd }}`
|
||||
alias __zoxide_hook 'set __zoxide_pwd_tmp = "`{{ pwd_cmd }}`"; test "$__zoxide_pwd_tmp" != "$__zoxide_pwd_old" && zoxide add -- "$__zoxide_pwd_tmp"; set __zoxide_pwd_old = "$__zoxide_pwd_tmp"'
|
||||
{%- endif %}
|
||||
|
||||
# Initialize hook.
|
||||
alias precmd ';__zoxide_hook'
|
||||
|
||||
{%- endif %}
|
||||
|
||||
{{ section }}
|
||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||
#
|
||||
|
||||
# Jump to a directory using only keywords.
|
||||
alias __zoxide_z 'set __zoxide_args = (\!*)\
|
||||
if ("$#__zoxide_args" == 0) then\
|
||||
cd ~\
|
||||
else\
|
||||
if ("$#__zoxide_args" == 1 && "$__zoxide_args[1]" == "-") then\
|
||||
cd -\
|
||||
else if ("$#__zoxide_args" == 1 && -d "$__zoxide_args[1]") then\
|
||||
cd "$__zoxide_args[1]"\
|
||||
else\
|
||||
set __zoxide_pwd = `{{ pwd_cmd }}`\
|
||||
set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' -- $__zoxide_args`" && cd "$__zoxide_result"\
|
||||
endif\
|
||||
endif'
|
||||
|
||||
# Jump to a directory using interactive search.
|
||||
alias __zoxide_zi 'set __zoxide_args = (\!*)\
|
||||
set __zoxide_pwd = `{{ pwd_cmd }}`\
|
||||
set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' --interactive -- $__zoxide_args`" && cd "$__zoxide_result"'
|
||||
|
||||
{{ section }}
|
||||
# Commands for zoxide. Disable these using --no-cmd.
|
||||
#
|
||||
|
||||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
alias {{cmd}} __zoxide_z
|
||||
alias {{cmd}}i __zoxide_zi
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
||||
{{ section }}
|
||||
# To initialize zoxide, add this to your shell configuration file (usually ~/.tcshrc):
|
||||
#
|
||||
# zoxide init tcsh > ~/.zoxide.tcsh
|
||||
# source ~/.zoxide.tcsh
|
|
@ -64,7 +64,7 @@ class ZoxideSilentException(Exception):
|
|||
|
||||
|
||||
def __zoxide_errhandler(
|
||||
func: typing.Callable[[list[str]], None]
|
||||
func: typing.Callable[[list[str]], None],
|
||||
) -> typing.Callable[[list[str]], int]:
|
||||
"""Print exception and exit with error code 1."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue