#!/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"