Skip to content

Instantly share code, notes, and snippets.

@santhoshtr
Created June 19, 2026 09:26
Show Gist options
  • Select an option

  • Save santhoshtr/cc920a9010e2a2ab094e768ee79a4fce to your computer and use it in GitHub Desktop.

Select an option

Save santhoshtr/cc920a9010e2a2ab094e768ee79a4fce to your computer and use it in GitHub Desktop.
wiki — a fast, fzf-based Wikipedia reader
#!/usr/bin/env bash
#
# wiki — a fast, fzf-based Wikipedia reader.
#
# Usage:
# wiki # English (default)
# wiki de # German, fr, es, ... (any Wikipedia language code)
#
# Type to live-search article titles via Wikipedia's prefixsearch API,
# read the plain-text article in the preview pane, press Enter to open it
# full-screen in your pager. Esc / Ctrl-C to quit.
#
# Dependencies: fzf, curl, jq, and `wikipedia-article-transform`.
set -euo pipefail
api_url() { echo "https://${WIKI_LANG:-en}.wikipedia.org/w/api.php"; }
# --- internal modes (fzf calls the script back through these) -----------
case "${1:-}" in
--search) # prefixsearch -> list of titles
query="${2:-}"
[ -z "$query" ] && exit 0
curl -fsS -G "$(api_url)" \
--data-urlencode "action=query" \
--data-urlencode "list=prefixsearch" \
--data-urlencode "psnamespace=0" \
--data-urlencode "pslimit=${WIKI_LIMIT:-30}" \
--data-urlencode "pssearch=${query}" \
--data-urlencode "format=json" 2>/dev/null \
| jq -r '.query.prefixsearch[]?.title' 2>/dev/null || true
exit 0
;;
--show) # plain-text article (preview + reader)
title="${2:-}"
[ -z "$title" ] && exit 0
exec wikipedia-article-transform fetch -l "${WIKI_LANG:-en}" -t "$title" -f plain
;;
esac
# --- main ---------------------------------------------------------------
WIKI_LANG="${1:-en}"
export WIKI_LANG
for cmd in fzf curl jq wikipedia-article-transform; do
command -v "$cmd" >/dev/null 2>&1 \
|| { echo "wiki: missing dependency: $cmd" >&2; exit 1; }
done
# Absolute path to this script, so fzf can call back into it.
WIKI_SELF="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
export WIKI_SELF
: | fzf \
--disabled \
--no-sort \
--prompt "wiki:${WIKI_LANG}> " \
--header 'type to search · Enter: read · Esc: quit' \
--bind 'change:reload:"$WIKI_SELF" --search {q}' \
--bind 'enter:execute("$WIKI_SELF" --show {} | ${PAGER:-less -R})' \
--preview '"$WIKI_SELF" --show {}' \
--preview-window 'right:62%:wrap'
@santhoshtr

Copy link
Copy Markdown
Author

Screenshot:

image

@santhoshtr

santhoshtr commented Jun 19, 2026

Copy link
Copy Markdown
Author

wikipedia-article-transform can be installed using cargo or uv
Refer https://thottingal.in/blog/2026/03/14/wikipedia-article-transform/

It supports markdown too. So if there is a good terminal based markdown previewer, fzf can use that for --preview option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment