Created
June 19, 2026 09:26
-
-
Save santhoshtr/cc920a9010e2a2ab094e768ee79a4fce to your computer and use it in GitHub Desktop.
wiki — a fast, fzf-based Wikipedia reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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' |
Author
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
Screenshot: