From 86741bbe6a34b30ae632dee09ff17a7a68b62a2e Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Sun, 8 Jan 2023 07:51:03 +0530 Subject: [PATCH] Define completions on __zoxide_z --- CHANGELOG.md | 6 ++++++ templates/fish.txt | 14 ++++---------- templates/zsh.txt | 34 ++++++++++++---------------------- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d9701..b8a2052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,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 + +### Added + +- Fish/Zsh: Aliases on `__zoxide_z` will now use completions. + ## [0.9.0] - 2023-01-08 ### Added diff --git a/templates/fish.txt b/templates/fish.txt index 4a8a5bf..65de458 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -83,7 +83,7 @@ function __zoxide_z end end -# Completions for `z`. +# Completions. function __zoxide_z_complete set -l tokens (commandline --current-process --tokenize) set -l curr_tokens (commandline --cut-at-cursor --current-process --tokenize) @@ -99,6 +99,7 @@ function __zoxide_z_complete commandline --function repaint end end +complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)' # Jump to a directory using interactive search. function __zoxide_zi @@ -114,17 +115,10 @@ end {%- when Some with (cmd) %} abbr --erase {{cmd}} &>/dev/null -complete --command {{cmd}} --erase -function {{cmd}} - __zoxide_z $argv -end -complete --command {{cmd}} --no-files --arguments '(__zoxide_z_complete)' +alias {{cmd}}=__zoxide_z abbr --erase {{cmd}}i &>/dev/null -complete --command {{cmd}}i --erase -function {{cmd}}i - __zoxide_zi $argv -end +alias {{cmd}}i=__zoxide_zi {%- when None %} diff --git a/templates/zsh.txt b/templates/zsh.txt index cfa9bb1..d261a31 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -79,23 +79,7 @@ function __zoxide_zi() { result="$(\command zoxide query -i -- "$@")" && __zoxide_cd "${result}" } -{{ section }} -# Commands for zoxide. Disable these using --no-cmd. -# - -{%- match cmd %} -{%- when Some with (cmd) %} - -\builtin unalias {{cmd}} &>/dev/null || \builtin true -function {{cmd}}() { - __zoxide_z "$@" -} - -\builtin unalias {{cmd}}i &>/dev/null || \builtin true -function {{cmd}}i() { - __zoxide_zi "$@" -} - +# Completions. if [[ -o zle ]]; then function __zoxide_z_complete() { # Only show completions when the cursor is at the end of the line. @@ -118,13 +102,19 @@ if [[ -o zle ]]; then } \builtin bindkey '\e[0n' 'reset-prompt' - if [[ "${+functions[compdef]}" -ne 0 ]]; then - \compdef -d {{cmd}} - \compdef -d {{cmd}}i - \compdef __zoxide_z_complete {{cmd}} - fi + [[ "${+functions[compdef]}" -ne 0 ]] && \compdef __zoxide_z_complete __zoxide_z fi +{{ section }} +# Commands for zoxide. Disable these using --no-cmd. +# + +{%- match cmd %} +{%- when Some with (cmd) %} + +\builtin alias {{cmd}}=__zoxide_z +\builtin alias {{cmd}}i=__zoxide_zi + {%- when None %} {{ not_configured }}