From bc442f2a72051e965feb4be17181fdf3e6a3f167 Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 8 Mar 2021 17:06:53 -0500 Subject: .local/bin/fzf-doc: Cache path Read YAML files. --- .local/bin/fzf-doc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.local/bin/fzf-doc b/.local/bin/fzf-doc index bf3b49e..6f51c08 100755 --- a/.local/bin/fzf-doc +++ b/.local/bin/fzf-doc @@ -1,5 +1,8 @@ #!/bin/sh -eu +cache=$HOME/.cache/fzf-doc +documentation=/etc/documentation + fzf_doc_preview() { file=$1 extension=${file##*.} @@ -11,14 +14,20 @@ fzf_doc_preview() { esac } -[ "${1-}" = "--preview" ] && fzf_doc_preview "${2-}" && exit; - -grep -lRi \ +if [ ! -f "$cache" ] || test "$cache" -ot "$documentation"; then + grep -lRi \ --include=*.md \ --include=*.txt \ --include=*.pdf \ --include=*.html \ - "${1-.}" /etc/documentation \ + --include=*.yml \ + --include=*.yaml \ + . /etc/documentation > "$cache"; +fi + +[ "${1-}" = "--preview" ] && fzf_doc_preview "${2-}" && exit; + +grep -i "${1-.}" "$cache" \ | fzf --preview "fzf-doc --preview {}" \ | while read -r file @@ -28,6 +37,8 @@ do md) mdcat -cl "$file" | vim - ;; html) w3m -dump "$file" | vim - ;; pdf) pdftotext "$file" - | vim - ;; + yml) vim "$file" ;; + yaml) vim "$file" ;; *) vim "$file" ;; esac done -- cgit v1.2.3