Skip to content

Commit ccbea24

Browse files
committed
List more kinds of possible documents in zsh
1 parent 952b5f4 commit ccbea24

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

script/texdoclib-const.tlu

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,26 @@ __texdoc() {
6363
+ debug
6464
{{debug}}
6565
)
66-
_arguments -C -A $options \
67-
'*: :->arguments' && return
68-
case $state in
69-
arguments)
70-
local tlpdb="$(kpsewhich -var-value TEXMFROOT)/tlpkg/texlive.tlpdb"
71-
_values package $(awk '/^name[^.]*$/ {print $2}' $tlpdb)
72-
;;
73-
esac
66+
_arguments -C -A $options '*:document:__texdoc_argument'
67+
}
68+
69+
__texdoc_argument() {
70+
_alternative \
71+
"files:local documents:$(__texdoc_massage __texdoc_localfiles)" \
72+
"aliases:aliases:$(__texdoc_massage __texdoc_aliases)" \
73+
"packages:packages:$(__texdoc_massage __texdoc_packages)" \
74+
"pdf:documents:$(__texdoc_massage __texdoc_lsr pdf)" \
75+
}
76+
77+
# stdout of $@ is split at linebreaks, ordered, element-wise quoted, space joined, and ripped of empty words
78+
__texdoc_massage() { echo \(${(j: :)${(@q)${(ou)${(f)"$($@ 2>/dev/null)"}}}:#"''"}\) }
79+
80+
__texdoc_localfiles() { find -L "$(kpsewhich -var-value TEXMFHOME)/doc" -type f -printf '%f\n' }
81+
__texdoc_aliases() { sed -n 's/^alias[^ ]* \(.*\) = .*$/\1/p' "${(f@)"$(texdoc --files|sed -n 's/^\s\+active\s\+//p')"}" }
82+
__texdoc_lsr() { grep -h "\\.$1$" "${(f@)"$(kpsewhich -all ls-R)"}" }
83+
__texdoc_packages() { # Use texlive.tlpdb if it exists, otherwise fallback to texdoc's own data
84+
sed -n '/\./!s/^name //p' "${(f@)"$(kpsewhich -all -cnf-line='TEXINPUTS={$TEXMFROOT,$TEXMFHOME}/tlpkg' -format=tex texlive.tlpdb)"}" \
85+
|| sed -n 's/^ \["\([^"]*\)"\] = {$/\1/p' "$(kpsewhich Data.tlpdb.lua)"
7486
}
7587
7688
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then

0 commit comments

Comments
 (0)