mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-11-22 12:55:13 +00:00
Improve completions (#562)
This commit is contained in:
parent
5de13befbc
commit
0b51cb6591
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@ -58,8 +58,5 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
- name: Run lints
|
- name: Run lints + tests
|
||||||
run: just lint
|
run: just lint test
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: just test
|
|
||||||
|
@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Nushell: add support for v0.78.0.
|
- Nushell: add support for v0.78.0.
|
||||||
- Fish: plugin now works on older versions.
|
- Fish: plugin now works on older versions.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fish: not providing `cd` completions when there is a space in the path.
|
||||||
|
- Bash/Fish/Zsh: providing `z` completions when the last argument starts with `z!`.
|
||||||
|
- Bash/Fish/Zsh: attempting to `cd` when the last argument is `z!`.
|
||||||
|
|
||||||
## [0.9.0] - 2023-01-08
|
## [0.9.0] - 2023-01-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -75,7 +75,7 @@ function __zoxide_z() {
|
|||||||
__zoxide_cd "${OLDPWD}"
|
__zoxide_cd "${OLDPWD}"
|
||||||
elif [[ $# -eq 1 && -d $1 ]]; then
|
elif [[ $# -eq 1 && -d $1 ]]; then
|
||||||
__zoxide_cd "$1"
|
__zoxide_cd "$1"
|
||||||
elif [[ ${@: -1} == "${__zoxide_z_prefix}"* ]]; then
|
elif [[ ${@: -1} == "${__zoxide_z_prefix}"?* ]]; then
|
||||||
# shellcheck disable=SC2124
|
# shellcheck disable=SC2124
|
||||||
\builtin local result="${@: -1}"
|
\builtin local result="${@: -1}"
|
||||||
__zoxide_cd "{{ "${result:${#__zoxide_z_prefix}}" }}"
|
__zoxide_cd "{{ "${result:${#__zoxide_z_prefix}}" }}"
|
||||||
@ -90,7 +90,7 @@ function __zoxide_z() {
|
|||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi() {
|
function __zoxide_zi() {
|
||||||
\builtin local result
|
\builtin local result
|
||||||
result="$(\command zoxide query -i -- "$@")" && __zoxide_cd "${result}"
|
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
@ -130,10 +130,10 @@ if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VER
|
|||||||
\builtin compgen -A directory -- "${COMP_WORDS[-1]}" || \builtin true
|
\builtin compgen -A directory -- "${COMP_WORDS[-1]}" || \builtin true
|
||||||
)
|
)
|
||||||
# If there is a space after the last word, use interactive selection.
|
# If there is a space after the last word, use interactive selection.
|
||||||
elif [[ -z ${COMP_WORDS[-1]} ]]; then
|
elif [[ -z ${COMP_WORDS[-1]} ]] && [[ ${COMP_WORDS[-2]} != "${__zoxide_z_prefix}"?* ]]; then
|
||||||
\builtin local result
|
\builtin local result
|
||||||
# shellcheck disable=SC2312
|
# shellcheck disable=SC2312
|
||||||
result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -i -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" &&
|
result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" &&
|
||||||
COMPREPLY=("${__zoxide_z_prefix}${result}/")
|
COMPREPLY=("${__zoxide_z_prefix}${result}/")
|
||||||
\builtin printf '\e[5n'
|
\builtin printf '\e[5n'
|
||||||
fi
|
fi
|
||||||
|
@ -68,7 +68,7 @@ edit:add-var __zoxide_z~ $__zoxide_z~
|
|||||||
fn __zoxide_zi {|@rest|
|
fn __zoxide_zi {|@rest|
|
||||||
var path
|
var path
|
||||||
try {
|
try {
|
||||||
set path = (zoxide query -i -- $@rest)
|
set path = (zoxide query --interactive -- $@rest)
|
||||||
} catch {
|
} catch {
|
||||||
} else {
|
} else {
|
||||||
__zoxide_cd $path
|
__zoxide_cd $path
|
||||||
|
@ -62,20 +62,21 @@ end
|
|||||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
#
|
#
|
||||||
|
|
||||||
set __zoxide_z_prefix 'z!'
|
if test -z $__zoxide_z_prefix
|
||||||
|
set __zoxide_z_prefix 'z!'
|
||||||
|
end
|
||||||
|
set __zoxide_z_prefix_regex ^(string escape --style=regex $__zoxide_z_prefix)
|
||||||
|
|
||||||
# Jump to a directory using only keywords.
|
# Jump to a directory using only keywords.
|
||||||
function __zoxide_z
|
function __zoxide_z
|
||||||
set -l argc (count $argv)
|
set -l argc (count $argv)
|
||||||
set -l prefix (string escape --style=regex $__zoxide_z_prefix)
|
|
||||||
|
|
||||||
if test $argc -eq 0
|
if test $argc -eq 0
|
||||||
__zoxide_cd $HOME
|
__zoxide_cd $HOME
|
||||||
else if test "$argv" = -
|
else if test "$argv" = -
|
||||||
__zoxide_cd -
|
__zoxide_cd -
|
||||||
else if test $argc -eq 1 -a -d $argv[1]
|
else if test $argc -eq 1 -a -d $argv[1]
|
||||||
__zoxide_cd $argv[1]
|
__zoxide_cd $argv[1]
|
||||||
else if set -l result (string replace --regex ^$prefix $argv[-1])
|
else if set -l result (string replace --regex $__zoxide_z_prefix_regex '' $argv[-1]); and test -n $result
|
||||||
__zoxide_cd $result
|
__zoxide_cd $result
|
||||||
else
|
else
|
||||||
set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
|
set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
|
||||||
@ -90,11 +91,12 @@ function __zoxide_z_complete
|
|||||||
|
|
||||||
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
|
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
|
||||||
# If there are < 2 arguments, use `cd` completions.
|
# If there are < 2 arguments, use `cd` completions.
|
||||||
__fish_complete_directories "$tokens[2]" ''
|
complete --do-complete "'' "(commandline --cut-at-cursor --current-token) | string match --regex '.*/$'
|
||||||
else if test (count $tokens) -eq (count $curr_tokens)
|
else if test (count $tokens) -eq (count $curr_tokens); and ! string match --quiet --regex $__zoxide_z_prefix_regex. $tokens[-1]
|
||||||
# If the last argument is empty, use interactive selection.
|
# If the last argument is empty and the one before doesn't start with
|
||||||
|
# $__zoxide_z_prefix, use interactive selection.
|
||||||
set -l query $tokens[2..-1]
|
set -l query $tokens[2..-1]
|
||||||
set -l result (zoxide query --exclude (__zoxide_pwd) -i -- $query)
|
set -l result (zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
|
||||||
and echo $__zoxide_z_prefix$result
|
and echo $__zoxide_z_prefix$result
|
||||||
commandline --function repaint
|
commandline --function repaint
|
||||||
end
|
end
|
||||||
@ -103,7 +105,7 @@ complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)'
|
|||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi
|
function __zoxide_zi
|
||||||
set -l result (command zoxide query -i -- $argv)
|
set -l result (command zoxide query --interactive -- $argv)
|
||||||
and __zoxide_cd $result
|
and __zoxide_cd $result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ def-env __zoxide_z [...rest:string] {
|
|||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
def-env __zoxide_zi [...rest:string] {
|
def-env __zoxide_zi [...rest:string] {
|
||||||
cd $'(zoxide query -i -- $rest | str trim -r -c "\n")'
|
cd $'(zoxide query --interactive -- $rest | str trim -r -c "\n")'
|
||||||
{%- if echo %}
|
{%- if echo %}
|
||||||
echo $env.PWD
|
echo $env.PWD
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@ -74,7 +74,7 @@ __zoxide_z() {
|
|||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
__zoxide_zi() {
|
__zoxide_zi() {
|
||||||
__zoxide_result="$(\command zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
__zoxide_result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
|
@ -61,7 +61,7 @@ function __zoxide_z() {
|
|||||||
__zoxide_cd ~
|
__zoxide_cd ~
|
||||||
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
|
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
|
||||||
__zoxide_cd "$1"
|
__zoxide_cd "$1"
|
||||||
elif [[ "$@[-1]" == "${__zoxide_z_prefix}"* ]]; then
|
elif [[ "$@[-1]" == "${__zoxide_z_prefix}"?* ]]; then
|
||||||
# shellcheck disable=SC2124
|
# shellcheck disable=SC2124
|
||||||
\builtin local result="${@[-1]}"
|
\builtin local result="${@[-1]}"
|
||||||
__zoxide_cd "{{ "${result:${#__zoxide_z_prefix}}" }}"
|
__zoxide_cd "{{ "${result:${#__zoxide_z_prefix}}" }}"
|
||||||
@ -76,7 +76,7 @@ function __zoxide_z() {
|
|||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi() {
|
function __zoxide_zi() {
|
||||||
\builtin local result
|
\builtin local result
|
||||||
result="$(\command zoxide query -i -- "$@")" && __zoxide_cd "${result}"
|
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Completions.
|
# Completions.
|
||||||
@ -88,10 +88,10 @@ if [[ -o zle ]]; then
|
|||||||
|
|
||||||
if [[ "{{ "${#words[@]}" }}" -eq 2 ]]; then
|
if [[ "{{ "${#words[@]}" }}" -eq 2 ]]; then
|
||||||
_files -/
|
_files -/
|
||||||
elif [[ "${words[-1]}" == '' ]]; then
|
elif [[ "${words[-1]}" == '' ]] && [[ "${words[-2]}" != "${__zoxide_z_prefix}"?* ]]; then
|
||||||
\builtin local result
|
\builtin local result
|
||||||
# shellcheck disable=SC2086,SC2312
|
# shellcheck disable=SC2086,SC2312
|
||||||
if result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -i -- ${words[2,-1]})"; then
|
if result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- ${words[2,-1]})"; then
|
||||||
result="${__zoxide_z_prefix}${result}"
|
result="${__zoxide_z_prefix}${result}"
|
||||||
# shellcheck disable=SC2296
|
# shellcheck disable=SC2296
|
||||||
compadd -Q "${(q-)result}"
|
compadd -Q "${(q-)result}"
|
||||||
|
Loading…
Reference in New Issue
Block a user