### Install zoxide with winget on Windows Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Windows using the Windows Package Manager. ```sh winget install ajeetdsouza.zoxide ``` -------------------------------- ### Install zoxide with Scoop Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Windows using the Scoop package manager. ```sh scoop install zoxide ``` -------------------------------- ### Install Zoxide on Void Linux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Void Linux using the xbps package manager. ```sh xbps-install -S zoxide ``` -------------------------------- ### Install Zoxide on openSUSE Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on openSUSE Tumbleweed using the zypper package manager. ```sh zypper install zoxide ``` -------------------------------- ### Install Zoxide via Script (Linux/WSL) Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Use this command to download and run the official zoxide installation script. This is the recommended method for Linux and WSL environments. ```sh curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh ``` -------------------------------- ### Install zoxide with Chocolatey Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Windows using the Chocolatey package manager. ```sh choco install zoxide ``` -------------------------------- ### Install Zoxide on Solus Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Solus Linux using the eopkg package manager. ```sh eopkg install zoxide ``` -------------------------------- ### Initialize Zoxide in Xonsh Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Example command to initialize zoxide integration within the Xonsh shell by executing the zoxide init command. ```shell execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') ``` -------------------------------- ### Install Zoxide via Cargo Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide using the Rust package manager, Cargo. Ensure you have Rust and Cargo installed. ```sh cargo install zoxide --locked ``` -------------------------------- ### Install zoxide with MacPorts Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on macOS using MacPorts. ```sh port install zoxide ``` -------------------------------- ### Install Zoxide via Guix Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide using the Guix package manager. This is specific to systems using Guix. ```sh guix install zoxide ``` -------------------------------- ### Install Zoxide on Devuan Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Devuan (version 4.0+) using the apt package manager. ```sh apt install zoxide ``` -------------------------------- ### Zoxide Command Aliases and Completions Setup Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Sets up aliases and completions for zoxide commands (`z` and `zi`) if the `cmd` variable is set. It erases existing aliases and completions before setting new ones to avoid conflicts. ```fish abbr --erase z &>/dev/null complete --erase --command z alias z=__zoxide_z abbr --erase zi &>/dev/null complete --erase --command zi alias zi=__zoxide_zi ``` -------------------------------- ### Install Zoxide on Gentoo Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Gentoo Linux using the emerge command. It is available under app-shells/zoxide. ```sh emerge app-shells/zoxide ``` -------------------------------- ### Install Zoxide via asdf (Plugin) Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add the zoxide plugin to your asdf version manager and then install zoxide. This is useful for managing multiple tool versions. ```sh asdf plugin add zoxide https://github.com/nyrst/asdf-zoxide.git asdf install zoxide latest ``` -------------------------------- ### Install zoxide on BSD systems Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on FreeBSD, NetBSD, or DragonFly BSD using their respective package managers. ```sh pkg install zoxide ``` ```sh pkgin install zoxide ``` -------------------------------- ### Install Zoxide on Exherbo Linux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Exherbo Linux. This involves resolving repository and zoxide packages. ```sh cave resolve -x repository/rust cave resolve -x zoxide ``` -------------------------------- ### Install Zoxide via Nixpkgs Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide using the Nix package manager. This command is for NixOS or users managing their environment with Nix. ```sh nix-env -iA nixpkgs.zoxide ``` -------------------------------- ### Install zoxide on Android with Termux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Android devices using Termux. ```sh pkg install zoxide ``` -------------------------------- ### Install Zoxide on Fedora Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Fedora (version 32+) using the dnf package manager. ```sh dnf install zoxide ``` -------------------------------- ### Install Zoxide on Rhino Linux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Rhino Linux using the pacstall package manager with the zoxide-deb package. ```sh pacstall -I zoxide-deb ``` -------------------------------- ### Install Zoxide on Arch Linux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Arch Linux using the pacman package manager. It is available in the Arch Linux Extra repository. ```sh pacman -S zoxide ``` -------------------------------- ### Install Zoxide via Linuxbrew Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide using the Linuxbrew package manager. This is an option for users who prefer Homebrew on Linux. ```sh brew install zoxide ``` -------------------------------- ### Install Zoxide on Alpine Linux Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide on Alpine Linux using the apk package manager. Requires Alpine 3.13 or newer. ```sh apk add zoxide ``` -------------------------------- ### Install Zoxide via Conda Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Install zoxide using the conda-forge channel. This is suitable for users within the Anaconda or Miniconda ecosystem. ```sh conda install -c conda-forge zoxide ``` -------------------------------- ### Get Current Directory (PWD) Function for Zoxide Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Defines the `__zoxide_pwd` function to get the current working directory, respecting the `_ZO_RESOLVE_SYMLINKS` setting. It uses `builtin pwd -P` or `builtin pwd -L` based on the configuration and handles Windows path conversion. ```fish function __zoxide_pwd set -l pwd if set -q resolve_symlinks set -l pwd "builtin pwd -P" else set -l pwd "builtin pwd -L" end if cfg!(windows) command cygpath -w (eval $pwd) else eval $pwd end end ``` -------------------------------- ### Zsh Completion Setup for Zoxide Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/zsh.txt This snippet configures Zsh's zle (Z shell Line Editor) to provide custom completions for Zoxide. It includes helper functions for interactive completion and handling results. ```zsh if [[ -o zle ]]; then __zoxide_result='' function __zoxide_z_complete() { # Only show completions when the cursor is at the end of the line. # shellcheck disable=SC2154 [[ "{{ "${#words[@]}" }}" -eq "${CURRENT}" ]] || return 0 if [[ "{{ "${#words[@]}" }}" -eq 2 ]]; then # Show completions for local directories. _cd -/ elif [[ "${words[-1]}" == '' ]]; then # Show completions for Space-Tab. # shellcheck disable=SC2086 __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \builtin true)" --interactive -- ${words[2,-1]}) # Set a result to ensure completion doesn't re-run compadd -Q "" # Bind '\e[0n' to helper function. \builtin bindkey '\e[0n' '__zoxide_z_complete_helper' # Sends query device status code, which results in a '\e[0n' being sent to console input. \builtin printf '\e[5n' # Report that the completion was successful, so that we don't fall back # to another completion function. return 0 fi } function __zoxide_z_complete_helper() { if [[ -n "${__zoxide_result}" ]]; then # shellcheck disable=SC2034,SC2296 BUFFER="{{ cmd.unwrap_or("cd") }} ${(q-)__zoxide_result}" __zoxide_result='' \builtin zle reset-prompt \builtin zle accept-line else \builtin zle reset-prompt fi } \builtin zle -N __zoxide_z_complete_helper {%- if let Some(cmd) = cmd %} [[ "${+functions[compdef]}" -ne 0 ]] && \compdef __zoxide_z_complete {{ cmd }} {%- endif %} fi ``` -------------------------------- ### Get Current Environment Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Retrieves the current Xonsh environment variables as a dictionary. ```python def __zoxide_env() -> dict[str, str]: """Returns the current environment.""" return builtins.__xonsh__.env.detype() # type: ignore # pylint:disable=no-member ``` -------------------------------- ### Get Current Working Directory Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Determines the current working directory, respecting the _ZO_RESOLVE_SYMLINKS environment variable. ```python def __zoxide_pwd() -> str: """pwd based on the value of _ZO_RESOLVE_SYMLINKS.""" {%- if resolve_symlinks %} pwd = os.getcwd() {%- else %} pwd = __zoxide_env().get("PWD") if pwd is None: raise RuntimeError("$PWD not found") {%- endif %} return pwd ``` -------------------------------- ### Get Current Directory with Symlink Resolution Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt Determines the current working directory, respecting the _ZO_RESOLVE_SYMLINKS setting. On Windows, it uses cygpath to provide a Windows-style path. ```bash function __zoxide_pwd() { {%- decl pwd -%} {%- if resolve_symlinks -%} {%- let pwd = "\builtin pwd -P" -%} {%- else -%} {%- let pwd = "\builtin pwd -L" -%} {%- endif -%} {%- if cfg!(windows) %} \command cygpath -w "{{ pwd }}" {%- else -%} {{ pwd }} {%- endif %} } ``` -------------------------------- ### Get Current Working Directory for Zoxide Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt Retrieves the current working directory's path, specifically for file system locations, to be used by zoxide. ```powershell function global:__zoxide_pwd { $cwd = Microsoft.PowerShell.Management\Get-Location if ($cwd.Provider.Name -eq "FileSystem") { $cwd.ProviderPath } } ``` -------------------------------- ### Zoxide Initialization for Fish Shell Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Provides instructions on how to initialize zoxide for the Fish shell by adding `zoxide init fish | source` to the `~/.config/fish/config.fish` file. ```fish # zoxide init fish | source ``` -------------------------------- ### Basic zoxide Navigation Commands Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Demonstrates fundamental commands for navigating directories using zoxide. Use 'z' followed by keywords to jump to the most relevant directory. Supports partial matches, subdirectories, and relative paths. ```shell 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 a subdirectory starting with foo 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 ``` -------------------------------- ### Initialize zoxide for Fish Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add this command to your ~/.config/fish/config.fish to enable zoxide integration with Fish. ```sh zoxide init fish | source ``` -------------------------------- ### Initialize zoxide for Xonsh Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Integrate zoxide with Xonsh by adding this command to your ~/.xonshrc. ```python execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide') ``` -------------------------------- ### Zoxide Initialization for tcsh Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/tcsh.txt This section provides instructions on how to initialize zoxide for tcsh. It involves generating a configuration file and sourcing it in your shell's startup file. ```shell # To initialize zoxide, add this to your shell configuration file (usually ~/.tcshrc): # # zoxide init tcsh > ~/.zoxide.tcsh # source ~/.zoxide.tcsh ``` -------------------------------- ### Jump to Directory with Keywords Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Allows jumping to a directory using keywords. Handles cases for no arguments, '-', and direct directory paths. Queries zoxide for matching directories. ```python @__zoxide_errhandler def __zoxide_z(args: list[str]) -> None: """Jump to a directory using only keywords.""" if args == []: __zoxide_cd() elif args == ["-"]: __zoxide_cd("-") elif len(args) == 1 and os.path.isdir(args[0]): __zoxide_cd(args[0]) else: try: zoxide = __zoxide_bin() cmd = subprocess.run( [zoxide, "query", "--exclude", __zoxide_pwd(), "--"] + args, check=True, env=__zoxide_env(), stdout=subprocess.PIPE, ) except subprocess.CalledProcessError as exc: raise ZoxideSilentException() from exc result = cmd.stdout[:-1] __zoxide_cd(result) ``` -------------------------------- ### Initialize zoxide for Nushell Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Configure Nushell to use zoxide by sourcing a generated configuration file. Requires Nushell v0.89.0+. ```sh zoxide init nushell | save -f ~/.zoxide.nu source ~/.zoxide.nu ``` -------------------------------- ### Zoxide Initialization Instruction Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt Provides instructions on how to initialize zoxide in PowerShell by invoking the zoxide init command and piping its output to Out-String, then executing it. ```powershell # Invoke-Expression (& { (zoxide init powershell | Out-String) }) ``` -------------------------------- ### Initialize zoxide for Zsh Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add this command to your ~/.zshrc to enable zoxide integration with Zsh. ```sh eval "$(zoxide init zsh)" ``` -------------------------------- ### Initialize zoxide for Elvish Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add this command to your ~/.elvish/rc.elv to enable zoxide integration with Elvish. Requires Elvish v0.18.0+. ```sh eval (zoxide init elvish | slurp) ``` -------------------------------- ### Zoxide 'z' Command for Directory Jumping Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Implements the `__zoxide_z` function, which allows jumping to directories using keywords. It handles various argument scenarios, including no arguments (jumps to HOME), '-' (jumps to previous directory), a single directory path, or a path prefixed with '--'. Otherwise, it queries zoxide for matching directories. ```fish function __zoxide_z set -l argc (builtin count $argv) if test $argc -eq 0 __zoxide_cd $HOME else if test "$argv" = - __zoxide_cd - else if test $argc -eq 1 -a -d $argv[1] __zoxide_cd $argv[1] else if test $argc -eq 2 -a $argv[1] = -- __zoxide_cd -- $argv[2] else set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv) and __zoxide_cd $result end end ``` -------------------------------- ### Import Data from Compatible Plugins Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Use the 'zoxide import' command followed by the plugin name to migrate data into Zoxide. This is useful if you are switching from other navigation tools. ```sh zoxide import ``` ```sh zoxide import atuin ``` ```sh zoxide import autojump ``` ```sh zoxide import fasd ``` ```sh zoxide import z ``` ```sh zoxide import z.lua ``` ```sh zoxide import zsh-z ``` -------------------------------- ### Interactive zoxide Navigation Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Shows how to use zoxide for interactive directory selection. The 'zi' command, often integrated with tools like fzf, allows for a fuzzy-finding experience to choose the target directory. ```shell zi foo # cd with interactive selection (using fzf) ``` -------------------------------- ### Zoxide Initialization for POSIX Shells Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/posix.txt Provides the command to initialize Zoxide in a POSIX shell configuration file. It uses `eval` to execute the output of `zoxide init posix --hook prompt`, ensuring Zoxide is properly integrated. ```sh # To initialize zoxide, add this to your configuration: # # eval "$(zoxide init posix --hook prompt)" ``` -------------------------------- ### Elvish Zoxide Initialization Hook Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Sets up Elvish hooks to integrate zoxide's directory tracking. It initializes a 'before-chdir' hook to store the previous directory and an 'after-chdir' hook to add the current directory to zoxide, depending on the hook configuration. ```elvish var oldpwd = $builtin:pwd set builtin:before-chdir = [$@builtin:before-chdir {|_| set oldpwd = $builtin:pwd }] {%- if hook == InitHook::None %} {{ not_configured }} {%- else %} if (builtin:not (builtin:eq $E:__zoxide_shlvl $E:SHLVL)) { set E:__zoxide_shlvl = $E:SHLVL {%- if hook == InitHook::Prompt %} set edit:before-readline = [$@edit:before-readline {|| zoxide add -- $pwd }] {%- else if hook == InitHook::Pwd %} set builtin:after-chdir = [$@builtin:after-chdir {|_| zoxide add -- $pwd }] {%- endif %} } {%- endif %} ``` -------------------------------- ### Initialize zoxide for PowerShell Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add this command to your PowerShell profile to enable zoxide integration. ```powershell Invoke-Expression (& { (zoxide init powershell | Out-String) }) ``` -------------------------------- ### zoxide Tab Completion for Directories Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Illustrates how zoxide provides interactive directory completions using tab completion. This feature is available on specific shell versions and requires pressing SPACE followed by TAB. ```shell z foo # show interactive completions (bash 4.4+/fish/zsh only) ``` -------------------------------- ### Elvish Zoxide Initialization Snippet Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Provides the command to initialize zoxide within the Elvish shell configuration file. Requires Elvish v0.18.0 or higher. ```elvish eval (zoxide init elvish | slurp) ``` -------------------------------- ### Initialize Zoxide for Bash Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt This command initializes Zoxide for your Bash shell. Add it to your shell configuration file (e.g., ~/.bashrc) to enable Zoxide functionality on startup. ```bash eval "$(zoxide init bash)" ``` -------------------------------- ### Initialize Zoxide for POSIX Shell Source: https://github.com/ajeetdsouza/zoxide/blob/main/README.md Add this line to the end of your shell configuration file to initialize Zoxide for POSIX-compliant shells, including the prompt hook. ```sh eval "$(zoxide init posix --hook prompt)" ``` -------------------------------- ### Add Zoxide Initialization to Nushell Environment Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt Provides instructions on how to add zoxide initialization to your Nushell environment. It involves saving the zoxide configuration to a file and sourcing it in your Nushell config file. Note the Nushell version requirement. ```nushell zoxide init nushell | save -f ~/.zoxide.nu source ~/.zoxide.nu ``` -------------------------------- ### Initialize Zoxide Prompt Hook Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt Initializes the zoxide hook system by setting a flag and overriding the prompt function to call the zoxide hook. This ensures new entries are added to the database automatically. ```powershell $global:__zoxide_hooked = (Microsoft.PowerShell.Utility\Get-Variable __zoxide_hooked -ErrorAction Ignore -ValueOnly) if ($global:__zoxide_hooked -ne 1) { $global:__zoxide_hooked = 1 $global:__zoxide_prompt_old = $function:prompt function global:prompt { if ($null -ne $__zoxide_prompt_old) { & $__zoxide_prompt_old } $null = __zoxide_hook } } ``` -------------------------------- ### Zoxide 'z' Command Completion Logic Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Defines the completion logic for the `__zoxide_z` command. It uses `cd` completions for initial arguments and interactive zoxide query for more complex cases, allowing users to select directories interactively. ```fish function __zoxide_z_complete set -l tokens (builtin commandline --current-process --tokenize) set -l curr_tokens (builtin commandline --cut-at-cursor --current-process --tokenize) if test (builtin count $tokens) -le 2 -a (builtin count $curr_tokens) -eq 1 complete --do-complete "'' "(builtin commandline --cut-at-cursor --current-token) | string match --regex -- '.*/$' else if test (builtin count $tokens) -eq (builtin count $curr_tokens) set -l query $tokens[2..-1] set -l result (command zoxide query --exclude (__zoxide_pwd) --interactive -- $query) and __zoxide_cd $result and builtin commandline --function cancel-commandline repaint end end complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)' ``` -------------------------------- ### Zoxide Interactive Jump Function (zi) Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt Provides an interactive interface to search and jump to directories using zoxide. It queries zoxide for matching directories and then changes to the selected one. ```bash function __zoxide_zi() { __zoxide_doctor \builtin local result result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}" } ``` -------------------------------- ### Zoxide Initialization of Hooks Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/zsh.txt Initializes zoxide hooks by adding __zoxide_hook to either precmd_functions or chpwd_functions based on the hook configuration. ```zsh \builtin typeset -ga precmd_functions \builtin typeset -ga chpwd_functions # shellcheck disable=SC2034,SC2296 precmd_functions=("${(@)precmd_functions:#__zoxide_hook}") # shellcheck disable=SC2034,SC2296 chpwd_functions=("${(@)chpwd_functions:#__zoxide_hook}") {%- if hook == InitHook::Prompt %} precmd_functions+=(__zoxide_hook) {%- else if hook == InitHook::Pwd %} chpwd_functions+=(__zoxide_hook) {%- endif %} ``` -------------------------------- ### Zoxide 'z' Command for Directory Jumping Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/zsh.txt Jumps to a directory based on keywords. Handles cases for no arguments, a single argument (directory, '-', or number), or a specific path with '--'. ```zsh function __zoxide_z() { __zoxide_doctor if [[ "$#" -eq 0 ]]; then __zoxide_cd ~ elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]+$ ]] }; then __zoxide_cd "$1" elif [[ "$#" -eq 2 ]] && [[ "$1" = "--" ]]; then __zoxide_cd "$2" else \builtin local result # shellcheck disable=SC2312 result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" [[ -n "$result" ]] && __zoxide_cd "${result}" fi } ``` -------------------------------- ### Zoxide Hook for Adding Entries on Prompt or PWD Change Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Configures a hook (`__zoxide_hook`) that runs on either `fish_prompt` or `PWD` variable change. This hook adds the current directory to the zoxide database, but only if not in private mode. ```fish function __zoxide_hook --on-event fish_prompt test -z "$fish_private_mode" and command zoxide add -- (__zoxide_pwd) end ``` ```fish function __zoxide_hook --on-variable PWD test -z "$fish_private_mode" and command zoxide add -- (__zoxide_pwd) end ``` -------------------------------- ### Zoxide 'zi' Command for Interactive Search Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Provides the `__zoxide_zi` function for interactive directory searching with zoxide. It queries zoxide interactively and then uses `__zoxide_cd` to navigate to the selected directory. ```fish function __zoxide_zi set -l result (command zoxide query --interactive -- $argv) and __zoxide_cd $result end ``` -------------------------------- ### Elvish Zoxide Jump Function Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Defines the '__zoxide_z' function for jumping to directories using keywords. It handles cases for navigating to home, the previous directory, a specific directory, or a zoxide-queried path. ```elvish fn __zoxide_z {|@rest| if (builtin:eq [] $rest) { __zoxide_cd ~ } elif (builtin:eq [-] $rest) { __zoxide_cd $oldpwd } elif (and ('builtin:==' (builtin:count $rest) 1) (path:is-dir &follow-symlink=$true $rest[0])) { __zoxide_cd $rest[0] } else { var path try { set path = (zoxide query --exclude $pwd -- $@rest) } catch { } else { __zoxide_cd $path } } } edit:add-var __zoxide_z~ $__zoxide_z~ ``` -------------------------------- ### Initialize Zoxide Hook Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt Initializes the zoxide hook by ensuring that the __zoxide_hook function is added to the PROMPT_COMMAND. It handles cases where PROMPT_COMMAND is unset or already contains other commands. ```bash if [[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]]; then if [[ "$(declare -p PROMPT_COMMAND 2>&1)" == "declare -a"* ]]; then PROMPT_COMMAND=("${PROMPT_COMMAND[@]}" __zoxide_hook) else # shellcheck disable=SC2128,SC2178 PROMPT_COMMAND="${PROMPT_COMMAND%${PROMPT_COMMAND##*[![:space:];]}"} # shellcheck disable=SC2128,SC2178 PROMPT_COMMAND="${PROMPT_COMMAND:+"${PROMPT_COMMAND}";}"__zoxide_hook" fi fi ``` -------------------------------- ### Configure Zoxide Pre-Prompt Hook in Nushell Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt This snippet configures the 'pre_prompt' hook for zoxide in Nushell. It ensures that zoxide is initialized to add new entries to its database when you navigate directories. This is typically used when zoxide is not automatically configured. ```nushell $env.config = ( $env.config? | default {} | upsert hooks { default {} } | upsert hooks.pre_prompt { default [] } ) let __zoxide_hooked = ( $env.config.hooks.pre_prompt | any { try { get __zoxide_hook } catch { false } } ) if not $__zoxide_hooked { $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append { __zoxide_hook: true, code: {|| ^zoxide add -- $env.PWD} }) } ``` -------------------------------- ### Zoxide Binary Execution Utility Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt This function executes the zoxide binary and captures its output as a UTF-8 string. It ensures the correct encoding is used during execution. ```powershell function global:__zoxide_bin { $encoding = [Console]::OutputEncoding try { [Console]::OutputEncoding = [System.Text.Utf8Encoding]::new() $result = zoxide @args return $result } finally { [Console]::OutputEncoding = $encoding } } ``` -------------------------------- ### Zoxide Jump Function (z) Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt Jumps to a directory based on keywords. Handles various cases including jumping to home, previous directory, a specific path, or a zoxide-queried path. It also supports jumping to paths prefixed with 'z#'. ```bash function __zoxide_z() { __zoxide_doctor # shellcheck disable=SC2199 if [[ $# -eq 0 ]]; then __zoxide_cd ~ elif [[ $# -eq 1 && $1 == '-' ]]; then __zoxide_cd "${OLDPWD}" elif [[ $# -eq 1 && -d $1 ]]; then __zoxide_cd "$1" elif [[ $# -eq 2 && $1 == '--' ]]; then __zoxide_cd "$2" elif [[ ${@: -1} == "${__zoxide_z_prefix}"?* ]]; then # shellcheck disable=SC2124 \builtin local result="${@: -1}" __zoxide_cd "{{ "${result:${#__zoxide_z_prefix}}" }}" else \builtin local result # shellcheck disable=SC2312 result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" && __zoxide_cd "${result}" fi } ``` -------------------------------- ### Zoxide CD Function with Custom Logic Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Provides the `__zoxide_cd` function, which enhances the `cd` command with zoxide's logic. It includes infinite loop detection and optionally echoes the PWD after changing directories based on the `_ZO_ECHO` setting. ```fish function __zoxide_cd if set -q __zoxide_loop builtin echo "zoxide: infinite loop detected" builtin echo "Avoid aliasing `cd` to `z` directly, use `zoxide init --cmd=cd fish` instead" return 1 end if cfg!(windows) __zoxide_loop=1 __zoxide_cd_internal (cygpath -u $argv) else __zoxide_loop=1 __zoxide_cd_internal $argv end if set -q echo and __zoxide_pwd end end ``` -------------------------------- ### Initialize Zoxide Hook Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/tcsh.txt This alias ensures that the zoxide hook function is executed before each command prompt. This is essential for the hook to function correctly. ```tcsh alias precmd ';__zoxide_hook' ``` -------------------------------- ### Elvish Zoxide Interactive Jump Function Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Defines the '__zoxide_zi' function for interactive directory searching and jumping using zoxide. It queries zoxide interactively and changes to the selected directory. ```elvish fn __zoxide_zi {|@rest| var path try { set path = (zoxide query --interactive -- $@rest) } catch { } else { __zoxide_cd $path } } edit:add-var __zoxide_zi~ $__zoxide_zi~ ``` -------------------------------- ### Zoxide Alias for Keyword-Based Jump Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/tcsh.txt This alias provides a 'z' command to jump to directories using keywords. It handles cases like jumping to home, the previous directory, or a specific directory, and uses zoxide's query to find the best match. ```tcsh 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 -P` set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' -- $__zoxide_args`" && cd "$__zoxide_result" endif endif' ``` -------------------------------- ### Find Zoxide Binary Path Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Locates the zoxide binary using xonsh's environment variable lookup. Defaults to 'zoxide' if not found. ```python def __zoxide_bin() -> str: """Finds and returns the location of the zoxide binary.""" zoxide = typing.cast(str, xonsh.environ.locate_binary("zoxide")) if zoxide is None: zoxide = "zoxide" return zoxide ``` -------------------------------- ### Elvish Zoxide Command Aliases and Completion Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Sets up aliases for zoxide jump commands ('z' and 'zi') and configures argument completers for them. This is conditional on the 'cmd' variable being set. ```elvish edit:add-var {{cmd}}~ $__zoxide_z~ edit:add-var {{cmd}}i~ $__zoxide_zi~ fn __zoxide_z_complete {|@rest| if (!= (builtin:count $rest) 2) { builtin:return } edit:complete-filename $rest[1] | builtin:each {|completion| var dir = $completion[stem] if (path:is-dir $dir) { builtin:put $dir } } } set edit:completion:arg-completer[{{cmd}}] = $__zoxide_z_complete~ ``` -------------------------------- ### Interactive Directory Jump Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Provides an interactive search interface to jump to directories using zoxide's query command. ```python @__zoxide_errhandler def __zoxide_zi(args: list[str]) -> None: """Jump to a directory using interactive search.""" try: zoxide = __zoxide_bin() cmd = subprocess.run( [zoxide, "query", "-i", "--"] + args, check=True, env=__zoxide_env(), stdout=subprocess.PIPE, ) except subprocess.CalledProcessError as exc: raise ZoxideSilentException() from exc result = cmd.stdout[:-1] __zoxide_cd(result) ``` -------------------------------- ### Zoxide Hook for Post-Prompt/Chdir Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Configures a hook to add the current directory to the zoxide database. This hook can be triggered on post-prompt or chdir events. ```python # Initialize hook to add new entries to the database. if "__zoxide_hook" not in globals(): {% if hook == InitHook::Prompt %} @builtins.events.on_post_prompt # type: ignore # pylint:disable=no-member {%- else if hook == InitHook::Pwd %} @builtins.events.on_chdir # type: ignore # pylint:disable=no-member {%- endif %} def __zoxide_hook(**_kwargs: typing.Any) -> None: """Hook to add new entries to the database.""" pwd = __zoxide_pwd() zoxide = __zoxide_bin() subprocess.run( [zoxide, "add", "--", pwd], check=False, env=__zoxide_env(), ) ``` -------------------------------- ### Zoxide Alias for Interactive Jump Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/tcsh.txt This alias provides a 'zi' command for interactive directory jumping. It allows you to search for directories interactively and then jump to the selected one. ```tcsh alias __zoxide_zi 'set __zoxide_args = (!*) set __zoxide_pwd = `pwd -P` set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' --interactive -- $__zoxide_args`" && cd "$__zoxide_result"' ``` -------------------------------- ### Internal CD Function Wrapper for Zoxide Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/fish.txt Wraps the internal `cd` function to prevent infinite loops when aliasing `cd` to `z`. It sources the original `cd.fish` function and renames it to `__zoxide_cd_internal`. ```fish if ! builtin functions --query __zoxide_cd_internal if status list-files functions/cd.fish &>/dev/null status get-file functions/cd.fish | string replace --regex -- '^function cd\s' 'function __zoxide_cd_internal ' source else string replace --regex -- '^function cd\s' 'function __zoxide_cd_internal ' < $__fish_data_dir/functions/cd.fish | source end end ``` -------------------------------- ### Change Directory with Zoxide Logic Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/xonsh.txt Changes the directory using xonsh's cd function, with optional echo of the new path if _ZO_ECHO is set. ```python def __zoxide_cd(path: str | bytes | None = None) -> None: """cd + custom logic based on the value of _ZO_ECHO.""" if path is None: args = [] elif isinstance(path, bytes): args = [path.decode("utf-8")] else: args = [path] _, exc, _ = xonsh.dirstack.cd(args) if exc is not None: raise RuntimeError(exc) {%- if echo %} print(__zoxide_pwd()) {%- endif %} ``` -------------------------------- ### Elvish CD Hook with Echo Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/elvish.txt Customizes the 'cd' behavior in Elvish to optionally echo the current directory after changing it, based on the _ZO_ECHO variable. ```elvish fn __zoxide_cd {|path| builtin:cd $path {%- if echo %} builtin:echo $pwd {%- endif %} } ``` -------------------------------- ### Zoxide Directory Change Logic Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt Handles changing directories using zoxide, with special logic for '-' and '+' arguments and PowerShell version compatibility. It also supports literal path changes. ```powershell function global:__zoxide_cd($dir, $literal) { $dir = if ($literal) { if ($null -eq $dir) { Microsoft.PowerShell.Management\Set-Location } else { Microsoft.PowerShell.Management\Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop } } else { if ($dir -eq '-' -and ($PSVersionTable.PSVersion -lt 6.1)) { Microsoft.PowerShell.Utility\Write-Error "cd - is not supported below PowerShell 6.1. Please upgrade your version of PowerShell." } elseif ($dir -eq '+' -and ($PSVersionTable.PSVersion -lt 6.2)) { Microsoft.PowerShell.Utility\Write-Error "cd + is not supported below PowerShell 6.2. Please upgrade your version of PowerShell." } else { Microsoft.PowerShell.Management\Set-Location -Path $dir -Passthru -ErrorAction Stop } } {%- if echo %} Microsoft.PowerShell.Utility\Write-Output $dir.Path {%- endif %} } ``` -------------------------------- ### Zoxide POSIX Hook Configuration (Prompt) Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/posix.txt Configures the Zoxide hook for POSIX shells when using the 'prompt' initialization method. This hook adds new entries to the Zoxide database and includes a doctor function to report potential configuration issues. ```sh # Hook to add new entries to the database. __zoxide_hook() { \command zoxide add -- "$(__zoxide_pwd || \command true)" } # Initialize hook. 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 %} } ``` -------------------------------- ### Zoxide Prompt Hook for Database Updates Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt This hook function is called on each prompt to add the current directory to the zoxide database if it's a file system path. ```powershell function global:__zoxide_hook { $result = __zoxide_pwd if ($null -ne $result) { zoxide add "--" $result } } ``` -------------------------------- ### Configure Zoxide PWD Environment Change Hook in Nushell Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt This snippet configures the 'env_change' hook for the 'PWD' variable in zoxide for Nushell. It ensures that zoxide is initialized to track directory changes automatically. This is an alternative to the 'pre_prompt' hook. ```nushell $env.config = ( $env.config? | default {} | upsert hooks { default {} } | upsert hooks.env_change { default {} } | upsert hooks.env_change.PWD { default [] } ) let __zoxide_hooked = ( $env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } } ) if not $__zoxide_hooked { $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { __zoxide_hook: true, code: {|_, dir| ^zoxide add -- $dir} }) } ``` -------------------------------- ### Bash Zoxide Completion Script Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt This script provides advanced tab completion for the 'z' command in Bash. It includes logic for interactive selection and directory completion based on Bash version and shell options. ```bash # - 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 function __zoxide_z_complete_helper() { READLINE_LINE="{{ cmd }} ${__zoxide_result@Q}" READLINE_POINT={{ "${#READLINE_LINE}" }} bind '"\e[0n": accept-line' \builtin printf '\e[5n' >/dev/tty } function __zoxide_z_complete() { # Only show completions when the cursor is at the end of the line. [[ {{ "${#COMP_WORDS[@]}" }} -eq $((COMP_CWORD + 1)) ]] || return # If there is only one argument, use `cd` completions. if [[ {{ "${#COMP_WORDS[@]}" }} -eq 2 ]]; then \builtin mapfile -t COMPREPLY < <( \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]} ]]; then # shellcheck disable=SC2312 __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 } \builtin complete -F __zoxide_z_complete -o filenames -- {{cmd}} \builtin complete -r {{cmd}}i &>/dev/null || \builtin true fi ``` -------------------------------- ### Zoxide Interactive 'zi' Command Alias Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/powershell.txt This function provides the 'zi' command for zoxide, enabling interactive searching and selection of directories. It uses the zoxide binary with the '-i' flag. ```powershell function global:__zoxide_zi { $result = __zoxide_bin query -i "--" @args if ($LASTEXITCODE -eq 0) { __zoxide_cd $result $true } } ``` -------------------------------- ### Configure Zoxide Hook for Prompt Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/tcsh.txt This snippet configures zoxide to add the current directory to its database whenever the prompt is displayed. It's useful for automatically tracking visited directories. ```tcsh alias __zoxide_hook 'zoxide add -- "`pwd -P`"' ``` -------------------------------- ### Define Zoxide Interactive 'zi' Alias in Nushell Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt Defines the '__zoxide_zi' internal function as the 'zi' command alias in Nushell. This enables interactive directory searching and jumping. It uses zoxide's interactive query mode. ```nushell def --env --wrapped __zoxide_zi [...rest:string] { cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")' if $env.echo { echo $env.PWD } } ``` -------------------------------- ### Zoxide PWD Utility Function Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/zsh.txt Determines the current working directory, respecting the _ZO_RESOLVE_SYMLINKS setting. On Windows, it uses cygpath to convert the path. ```zsh function __zoxide_pwd() { \builtin pwd -P \builtin pwd -L \command cygpath -w "${pwd}" } ``` -------------------------------- ### Zoxide Prompt Hook for Adding Entries Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/bash.txt A Bash function that adds the current directory to the zoxide database after a command executes. This hook is intended for use with InitHook::Prompt. ```bash function __zoxide_hook() { \builtin local -r retval="$?" # shellcheck disable=SC2312 \command zoxide add -- "$(__zoxide_pwd)" return "${retval}" } ``` -------------------------------- ### Define Zoxide 'z' Alias in Nushell Source: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt Defines the '__zoxide_z' internal function as the 'z' command alias in Nushell. This allows you to jump to directories using keywords. It handles cases with no arguments, a single hyphen, or a valid directory path. ```nushell def --env --wrapped __zoxide_z [...rest: string] { let path = match $rest { [] => {'~'}, [ '-' ] => {'-'}, [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} _ => { ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" } } cd $path if $env.echo { echo $env.PWD } } ```