Skip to content

Commit

Permalink
Merge branch 'ajeetdsouza:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
danie-dejager authored Aug 6, 2024
2 parents c915324 + 297499a commit a85fb2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 14 additions & 12 deletions templates/fish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ end
if test -z $__zoxide_z_prefix
set __zoxide_z_prefix 'z!'
end
set __zoxide_z_prefix_regex ^(string escape --style=regex $__zoxide_z_prefix)
set __zoxide_z_prefix_regex ^(string escape --style=regex -- $__zoxide_z_prefix)

# Jump to a directory using only keywords.
function __zoxide_z
set -l argc (count $argv)
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 if set -l result (string replace --regex -- $__zoxide_z_prefix_regex '' $argv[-1]); and test -n $result
__zoxide_cd $result
else
Expand All @@ -92,19 +94,19 @@ end

# Completions.
function __zoxide_z_complete
set -l tokens (commandline --current-process --tokenize)
set -l curr_tokens (commandline --cut-at-cursor --current-process --tokenize)
set -l tokens (builtin commandline --current-process --tokenize)
set -l curr_tokens (builtin commandline --cut-at-cursor --current-process --tokenize)

if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
if test (builtin count $tokens) -le 2 -a (builtin count $curr_tokens) -eq 1
# If there are < 2 arguments, use `cd` completions.
complete --do-complete "'' "(commandline --cut-at-cursor --current-token) | string match --regex '.*/$'
else if test (count $tokens) -eq (count $curr_tokens); and ! string match --quiet --regex $__zoxide_z_prefix_regex. $tokens[-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); and ! string match --quiet --regex -- $__zoxide_z_prefix_regex. $tokens[-1]
# 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 result (zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
and echo $__zoxide_z_prefix$result
commandline --function repaint
set -l result (command zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
and builtin echo $__zoxide_z_prefix$result
builtin commandline --function repaint
end
end
complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)'
Expand All @@ -122,10 +124,10 @@ end
{%- match cmd %}
{%- when Some with (cmd) %}

abbr --erase {{cmd}} &>/dev/null
builtin abbr --erase {{cmd}} &>/dev/null
alias {{cmd}}=__zoxide_z

abbr --erase {{cmd}}i &>/dev/null
builtin abbr --erase {{cmd}}i &>/dev/null
alias {{cmd}}i=__zoxide_zi

{%- when None %}
Expand Down
2 changes: 2 additions & 0 deletions templates/zsh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function __zoxide_z() {
__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
Expand Down

0 comments on commit a85fb2f

Please sign in to comment.