blob: 6f51c089e10b555ad98bd8e4649c71dc8d025b74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#!/bin/sh -eu
cache=$HOME/.cache/fzf-doc
documentation=/etc/documentation
fzf_doc_preview() {
file=$1
extension=${file##*.}
case "$extension" in
md) mdcat -l "$file" ;;
html) w3m -dump "$file" ;;
pdf) pdftotext "$file" - ;;
*) grep -hi -B 10 -A 10 . "${file}" ;;
esac
}
if [ ! -f "$cache" ] || test "$cache" -ot "$documentation"; then
grep -lRi \
--include=*.md \
--include=*.txt \
--include=*.pdf \
--include=*.html \
--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
do
extension=${file##*.}
case "$extension" in
md) mdcat -cl "$file" | vim - ;;
html) w3m -dump "$file" | vim - ;;
pdf) pdftotext "$file" - | vim - ;;
yml) vim "$file" ;;
yaml) vim "$file" ;;
*) vim "$file" ;;
esac
done
|