Files
fish-config/functions/zoxide.fish
T
rootiest e651566e14 docs(functions): split RETURNS into EXIT STATUS and stdout RETURNS
RETURNS previously conflated fish's $status exit code with genuine
stdout/printed output, e.g. rm listing "0/1" as if they were print
values rather than exit codes. Rename RETURNS to EXIT STATUS across
all 83 documented functions, and reintroduce RETURNS as a distinct
label reserved for the 15 functions that actually print to stdout.

Update build-manual.py's ENTRY_HEADS to render Exit Status before
Returns, manualtools.py's SECTIONS constant, and AGENTS.md's label
order and label-usage guidance to match. Add two verify-manual.py
regression tests: EXIT STATUS bodies must never contain stray
stdout/printed language, and Returns: must always render after
Exit Status: when both are present. Regenerate docs/fish-config.md.
2026-07-26 16:41:57 -04:00

79 lines
2.5 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Adapted from icezyclon/zoxide.fish (MIT)
# Heavily customized for Fish 4.x compatibility and performance
# SYNOPSIS
# _zoxide_z_complete [comp] [desc]
#
# DESCRIPTION
# Tab-completion handler for z/cd that merges standard filesystem completions
# (CWD, CDPATH) with zoxide frecency results. Called automatically by Fish
# during tab completion; not invoked directly.
#
# ARGUMENTS
# comp Currently completing token (read from commandline if omitted)
# desc Unused description argument
#
# EXAMPLE
# # Fired automatically during tab completion.
# z my<TAB>
function _zoxide_z_complete -d "Complete directory first or zoxide queries otherwise" --argument-names comp desc
# comp is the currently completing token
if not set -q comp[1]
set comp (commandline -ct)
end
# cmd are all tokens including the current one except the command
set -l cmd (commandline -opc) $comp
set -e cmd[1]
# 1. Get standard completions (CWD, CDPATH, etc.)
# We call the underlying functions directly to avoid recursion.
if test (count $cmd) -le 1
# CDPATH results
__fish_complete_cd
# Local directory results (CWD)
__fish_complete_directories "$comp" ""
end
# 2. Get zoxide results
# Cap results to 25 to avoid overwhelming the completion engine
set -l zresults (zoxide query -l $cmd | head -n 25)
for res in $zresults
set -l bname (basename $res)
# If the basename matches the prefix, show it as a short name.
if string match -qi "$comp*" -- $bname
printf "%s/\tzoxide: %s\n" $bname $res
end
# Also provide the absolute path. Fish will filter it if it doesn't match.
printf "%s/\tzoxide\n" $res
end
end
# SYNOPSIS
# _zoxide_equals_first_token <check>
#
# DESCRIPTION
# Tests whether the first non-switch token on the commandline equals the
# given string. Used internally to guard zoxide completion sources.
#
# ARGUMENTS
# check The string to compare against the first non-switch token
#
# EXIT STATUS
# 0 First token equals check
# 1 No token or token does not match
#
# EXAMPLE
# _zoxide_equals_first_token z
function _zoxide_equals_first_token -a check -d "Test if first non-switch token equals given one"
set -l tokens (commandline -co)
set -e tokens[1]
set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
if set -q tokens[1]
test $tokens[1] = $check
else
return 1
end
end