Skip to content

teal-bauer/wikitool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wikitool

A fast command-line tool to fetch Wikipedia content via the MediaWiki REST API.

Features

  • Supports all language Wikipedias (300+)
  • Accepts Wikipedia URLs directly—extracts language and title automatically
  • Multiple output formats: text, JSON, HTML
  • Single static binary with no dependencies

Installation

go install github.com/teal-bauer/wikitool@latest

Or build from source:

git clone https://github.com/teal-bauer/wikitool.git
cd wikitool
go build -o wikitool

Shell Completion

Generate completions for your shell:

# Bash
wikitool completion bash > /etc/bash_completion.d/wikitool

# Zsh
wikitool completion zsh > "${fpath[1]}/_wikitool"

# Fish
wikitool completion fish > ~/.config/fish/completions/wikitool.fish

# PowerShell
wikitool completion powershell | Out-String | Invoke-Expression

Run wikitool completion <shell> --help for detailed setup instructions.

Usage

# Get a page (returns wikitext source)
wikitool get Earth
wikitool get "Albert Einstein"

# Pass a Wikipedia URL directly
wikitool get https://de.wikipedia.org/wiki/Erde
wikitool get https://fr.wikipedia.org/wiki/Terre

# Get HTML instead of wikitext
wikitool get Jupiter --html

# Get metadata only
wikitool get Mars --info

# Follow redirects (like curl -L)
wikitool get "ISO 7064" -L

# Search Wikipedia
wikitool search "solar system"
wikitool search "quantum physics" --limit 20

# Search only in titles
wikitool search "einstein" --title

# Filter by category
wikitool search "waves" --category "Physics"

# Title autocomplete (typeahead)
wikitool search "einst" --autocomplete

# Different language
wikitool search "Tour Eiffel" --lang fr

# Get available language versions
wikitool languages Earth

# Get file/media info
wikitool file "File:The_Blue_Marble.jpg"

# Get revision details
wikitool revision 764138197

# JSON output
wikitool get Earth --output json
wikitool search "mars" --output json

Commands

Command Description
get <title|url> Get page content (aliases: page)
search <query> Search Wikipedia
languages <title> Get available language versions (aliases: langs)
file <title> Get file/media information
revision <id> Get revision details (aliases: rev)

Global Flags

Flag Description
-l, --lang Wikipedia language code (default: en)
-o, --output Output format: text, json, html (default: text)

Get Flags

Flag Description
--html Get rendered HTML instead of wikitext source
--info Get metadata only (no content)
-L, --location Follow redirects automatically

Search Syntax

Wikipedia uses CirrusSearch (Elasticsearch-based), which supports advanced query syntax:

Syntax Example Description
"phrase" "theory of relativity" Exact phrase match
intitle: intitle:einstein Search only in page titles
incategory: incategory:"Nobel laureates" Filter by category
* einst* Wildcard prefix matching
~ quantim~ Explicit fuzzy match (typo-tolerant by default)
- einstein -albert Exclude term from results
OR einstein OR feynman Boolean OR
hastemplate: hastemplate:Infobox Pages using a specific template
# Phrase search
wikitool search '"theory of relativity"'

# Title-only search
wikitool search "intitle:einstein"

# Exclude terms
wikitool search "physics -quantum"

# Category filter
wikitool search 'incategory:"Physics" waves'

License

GPL-3.0 - see LICENSE

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages