rc doc: Don't spawn processes unecessarily

This commit is contained in:
Frank LENORMAND 2021-09-16 11:47:44 +03:00
parent ab1704ce10
commit 1815a352f6

View File

@ -136,14 +136,15 @@ define-command -params 1 -hidden doc-render %{
define-command -params 0..2 \ define-command -params 0..2 \
-shell-script-candidates %{ -shell-script-candidates %{
if [ "$kak_token_to_complete" -eq 0 ]; then case "$kak_token_to_complete" in
0)
find -L \ find -L \
"${kak_config}/autoload/" \ "${kak_config}/autoload/" \
"${kak_runtime}/doc/" \ "${kak_runtime}/doc/" \
"${kak_runtime}/rc/" \ "${kak_runtime}/rc/" \
-type f -name "*.asciidoc" 2>/dev/null | -type f -name "*.asciidoc" 2>/dev/null |
sed 's,.*/,,; s/\.[^.]*$//' sed 's,.*/,,; s/\.[^.]*$//';;
elif [ "$kak_token_to_complete" -eq 1 ]; then 1)
page=$( page=$(
find -L \ find -L \
"${kak_config}/autoload/" \ "${kak_config}/autoload/" \
@ -157,8 +158,8 @@ define-command -params 0..2 \
/^==+ +/ { sub(/^==+ +/, ""); print } /^==+ +/ { sub(/^==+ +/, ""); print }
/^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print }
' < $page | tr '[A-Z ]' '[a-z-]' ' < $page | tr '[A-Z ]' '[a-z-]'
fi fi;;
fi esac
} \ } \
doc -docstring %{ doc -docstring %{
doc <topic> [<keyword>]: open a buffer containing documentation about a given topic doc <topic> [<keyword>]: open a buffer containing documentation about a given topic