aboutsummaryrefslogtreecommitdiff
path: root/wiki-search
blob: 15ee443bda5e83b2a1a19eab740a067a0ab5dcc0 (plain) (blame)
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
#!/usr/bin/env bash
# Live ripgrep through vimwiki, live preview, open match in vim at the line.
set -euo pipefail

wiki="${VIMWIKI_DIR:-$HOME/docs/vimwiki}"
[[ -d $wiki ]] || { echo "wiki dir not found: $wiki" >&2; exit 1; }
cd "$wiki"

rg_cmd='rg --color=always --line-number --no-heading --smart-case --glob "*.md"'

selection=$(
  fzf --ansi --disabled \
      --delimiter=':' \
      --bind="start:reload:$rg_cmd -- ''" \
      --bind="change:reload:$rg_cmd -- {q} || true" \
      --bind='ctrl-/:change-preview-window(hidden|right,60%,+{2}/2)' \
      --preview='batcat --color=always --style=numbers --highlight-line={2} -- {1} 2>/dev/null' \
      --preview-window='right,60%,+{2}/2' \
      --header='Type to search · Enter opens at line · Ctrl-/ toggles preview'
) || exit 0
[[ -z $selection ]] && exit 0

file=$(printf '%s' "$selection" | cut -d: -f1)
line=$(printf '%s' "$selection" | cut -d: -f2)

exec vim "+$line" "$file"