aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/fzf-doc
blob: f30f23e04690d66b029b6cb793f2e607ee09eb6a (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
#!/bin/sh -eu

fzf_doc_preview() {
  file=$1
  extension=${file##*.}
  case "$extension" in
    md) glow -w 60 "$file" ;;
    html) w3m -dump "$file" ;;
    *) grep -hi -B 10 -A 10 . "${file}" ;;
  esac
}

[ "${1-}" = "--preview" ] && fzf_doc_preview "${2-}" && exit;

grep -lRi \
  --include=*.md \
  --include=*.txt \
  --include=*.html \
  "${1-.}" /etc/documentation \
  | fzf --preview "fzf-doc --preview {}" \
  | while read -r doc

do
  extension=${doc##*.}
  case "$extension" in
    md) glow "$doc" | vim -;;
    html) w3m -dump "$doc" | vim - ;;
    *) vim "$doc" ;;
  esac
done