Define completions on __zoxide_z

This commit is contained in:
Ajeet D'Souza 2023-01-08 07:51:03 +05:30
parent 2555870c31
commit 86741bbe6a
3 changed files with 22 additions and 32 deletions

View File

@ -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

View File

@ -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 %}

View File

@ -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 }}