Skip to content

Commit

Permalink
Merge pull request #123 from mgkurtz/zsh-completion
Browse files Browse the repository at this point in the history
List more kinds of possible packages/documents/aliases in zsh completion
  • Loading branch information
wtsnjp authored Feb 1, 2025
2 parents 952b5f4 + ccbea24 commit 9535c1f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions script/texdoclib-const.tlu
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,26 @@ __texdoc() {
+ debug
{{debug}}
)
_arguments -C -A $options \
'*: :->arguments' && return
case $state in
arguments)
local tlpdb="$(kpsewhich -var-value TEXMFROOT)/tlpkg/texlive.tlpdb"
_values package $(awk '/^name[^.]*$/ {print $2}' $tlpdb)
;;
esac
_arguments -C -A $options '*:document:__texdoc_argument'
}
__texdoc_argument() {
_alternative \
"files:local documents:$(__texdoc_massage __texdoc_localfiles)" \
"aliases:aliases:$(__texdoc_massage __texdoc_aliases)" \
"packages:packages:$(__texdoc_massage __texdoc_packages)" \
"pdf:documents:$(__texdoc_massage __texdoc_lsr pdf)" \
}
# stdout of $@ is split at linebreaks, ordered, element-wise quoted, space joined, and ripped of empty words
__texdoc_massage() { echo \(${(j: :)${(@q)${(ou)${(f)"$($@ 2>/dev/null)"}}}:#"''"}\) }
__texdoc_localfiles() { find -L "$(kpsewhich -var-value TEXMFHOME)/doc" -type f -printf '%f\n' }
__texdoc_aliases() { sed -n 's/^alias[^ ]* \(.*\) = .*$/\1/p' "${(f@)"$(texdoc --files|sed -n 's/^\s\+active\s\+//p')"}" }
__texdoc_lsr() { grep -h "\\.$1$" "${(f@)"$(kpsewhich -all ls-R)"}" }
__texdoc_packages() { # Use texlive.tlpdb if it exists, otherwise fallback to texdoc's own data
sed -n '/\./!s/^name //p' "${(f@)"$(kpsewhich -all -cnf-line='TEXINPUTS={$TEXMFROOT,$TEXMFHOME}/tlpkg' -format=tex texlive.tlpdb)"}" \
|| sed -n 's/^ \["\([^"]*\)"\] = {$/\1/p' "$(kpsewhich Data.tlpdb.lua)"
}
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
Expand Down

0 comments on commit 9535c1f

Please sign in to comment.