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

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
}

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

grep -lRi \
  --include=*.md \
  --include=*.txt \
  --include=*.pdf \
  --include=*.html \
  "${1-.}" /etc/documentation \
  | 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 - ;;
    *) vim "$file" ;;
  esac
done