From ab1704ce108a7a7249f7417c4fec6aa2c8109944 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 16 Sep 2021 11:41:25 +0300 Subject: [PATCH 1/2] rc doc: Hide errors on missing directories Fixes #4273. --- rc/tools/doc.kak | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak index 111cfe1b..410f3d34 100644 --- a/rc/tools/doc.kak +++ b/rc/tools/doc.kak @@ -141,7 +141,7 @@ define-command -params 0..2 \ "${kak_config}/autoload/" \ "${kak_runtime}/doc/" \ "${kak_runtime}/rc/" \ - -type f -name "*.asciidoc" | + -type f -name "*.asciidoc" 2>/dev/null | sed 's,.*/,,; s/\.[^.]*$//' elif [ "$kak_token_to_complete" -eq 1 ]; then page=$( @@ -149,7 +149,7 @@ define-command -params 0..2 \ "${kak_config}/autoload/" \ "${kak_runtime}/doc/" \ "${kak_runtime}/rc/" \ - -type f -name "$1.asciidoc" | + -type f -name "$1.asciidoc" 2>/dev/null | head -1 ) if [ -f "${page}" ]; then @@ -176,7 +176,7 @@ define-command -params 0..2 \ "${kak_config}/autoload/" \ "${kak_runtime}/doc/" \ "${kak_runtime}/rc/" \ - -type f -name "$topic.asciidoc" | + -type f -name "$topic.asciidoc" 2>/dev/null | head -1 ) if [ -f "${page}" ]; then From 1815a352f690ca647160682e03d3e053a3bedfa3 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 16 Sep 2021 11:47:44 +0300 Subject: [PATCH 2/2] rc doc: Don't spawn processes unecessarily --- rc/tools/doc.kak | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak index 410f3d34..d5227ee4 100644 --- a/rc/tools/doc.kak +++ b/rc/tools/doc.kak @@ -136,29 +136,30 @@ define-command -params 1 -hidden doc-render %{ define-command -params 0..2 \ -shell-script-candidates %{ - if [ "$kak_token_to_complete" -eq 0 ]; then - find -L \ - "${kak_config}/autoload/" \ - "${kak_runtime}/doc/" \ - "${kak_runtime}/rc/" \ - -type f -name "*.asciidoc" 2>/dev/null | - sed 's,.*/,,; s/\.[^.]*$//' - elif [ "$kak_token_to_complete" -eq 1 ]; then - page=$( + case "$kak_token_to_complete" in + 0) find -L \ "${kak_config}/autoload/" \ "${kak_runtime}/doc/" \ "${kak_runtime}/rc/" \ - -type f -name "$1.asciidoc" 2>/dev/null | - head -1 - ) - if [ -f "${page}" ]; then - awk ' - /^==+ +/ { sub(/^==+ +/, ""); print } - /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } - ' < $page | tr '[A-Z ]' '[a-z-]' - fi - fi + -type f -name "*.asciidoc" 2>/dev/null | + sed 's,.*/,,; s/\.[^.]*$//';; + 1) + page=$( + find -L \ + "${kak_config}/autoload/" \ + "${kak_runtime}/doc/" \ + "${kak_runtime}/rc/" \ + -type f -name "$1.asciidoc" 2>/dev/null | + head -1 + ) + if [ -f "${page}" ]; then + awk ' + /^==+ +/ { sub(/^==+ +/, ""); print } + /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } + ' < $page | tr '[A-Z ]' '[a-z-]' + fi;; + esac } \ doc -docstring %{ doc []: open a buffer containing documentation about a given topic