Pokemon version of cowsay, powered by PokeAPI.
demo.mp4
Inspired by another pokemonsay and parrotsay-api I created this to
quell my obsession with Pokemon and command line greetings.
Simply call pokemonsay to get a random Wild POKEMON appeared! message.
Pipe to pokemonsay to get a random Pokemon with the piped message below it.
Install with Cargo:
cargo install pokemonsayOr use the Nix flake:
nix run 'github:dfrankland/pokemonsay'Run pokemonsay --help to see all available options.
Display a random Pokemon with the default message:
pokemonsayPipe a custom message to display with a random Pokemon:
echo "Your message here" | pokemonsay--query-method <METHOD>
- Specifies where to fetch Pokemon data from
- Options:
db,http - Default:
db(if embedded),http(otherwise) db: Queries a local SQLite database (faster, no rate limit)http: Queries PokeAPI GraphQL endpoint (rate limit: 200 queries/hour)
--db-path <PATH>
- Path to the PokeAPI SQLite database
- Can also be set via
POKEMONSAY_DB_PATHenvironment variable - Required when using
--query-method db(in non-embedded builds) - Example:
pokemonsay --db-path ./pokeapi.db
--sprites-retrieval-method <METHOD>
- Specifies where to fetch Pokemon sprite images from
- Options:
embedded,http - Default:
embedded(if available),http(otherwise) embedded: Uses sprites built into the CLI (fastest)http: Downloads from PokeAPI sprites repository
--pokemonsay-template <TEMPLATE>
- Template for the message displayed below the Pokemon sprite
- Uses TinyTemplate syntax with
{pokemon}as the Pokemon name placeholder - Default:
"Wild {pokemon} appeared!" - Example:
pokemonsay --pokemonsay-template "I choose you, {pokemon}!"
--crop-sprite-transparent-bg
- Flag to crop transparent pixels from the Pokemon sprite background
- When enabled, removes padding around the sprite for a tighter display
- Example:
pokemonsay --crop-sprite-transparent-bg
--max-sprite-dimension <DIMENSION>
- Maximum width or height for displaying the Pokemon sprite, preserving aspect ratio
- Set to
0to disable scaling (useful for terminals without image support) - Default:
30(for terminals that support Kitty, iTerm2, or Sixel graphics protocols),0(for others) - Example:
pokemonsay --max-sprite-dimension 50
These options are used in conjunction with the SQLite database from PokeAPI.
--db-pokemon-query <QUERY>
- Custom SQL query to fetch Pokemon data (when using
--query-method db) - Use
pokemonsay --helpto see the default query
--db-sprites-query <QUERY>
- Custom SQL query to fetch Pokemon sprite URLs (when using
--query-method db) - Use
pokemonsay --helpto see the default query
--db-species-name-query <QUERY>
- Custom SQL query to fetch Pokemon species names (when using
--query-method db) - Use
pokemonsay --helpto see the default query
This option is used in conjunction with the PokeAPI GraphQL endpoint which you can play with here: https://graphql.pokeapi.co/v1beta2/console/
--http-graphql-query <QUERY>
- Custom GraphQL query to fetch Pokemon data (when using
--query-method http) - Use
pokemonsay --helpto see the default query
Display with HTTP query method and custom template:
pokemonsay --query-method http --pokemonsay-template "{pokemon} is awesome!"Display with transparent background cropping and custom sprite size:
pokemonsay --crop-sprite-transparent-bg --max-sprite-dimension 40Use a custom database:
pokemonsay --query-method db --db-path /path/to/pokeapi.dbPipe a message with custom styling:
echo "๐ฎ Get ready for battle! ๐ฎ" | pokemonsay --crop-sprite-transparent-bgThis crate is built with a SQLite database from PokeAPI. The database and sprite assets can be included in the binary at compile-time or referenced at runtime, depending on your build configuration and needs.
The recommended way to build and package pokemonsay is with Nix, which
automates the PokeAPI database and sprites extraction:
nix build
# outputs the binary to `./result/bin/pokemonsay`This approach:
- Automatically fetches and builds the PokeAPI database and sprites
- Handles all dependencies reproducibly
- Produces a self-contained binary with embedded assets (by default)
If you're not using Nix, follow these steps:
-
Clone and build the PokeAPI database:
Clone the PokeAPI repository and follow its build instructions:
git clone --recurse-submodules https://github.com/PokeAPI/pokeapi.git cd ./pokeapi make setup make build-db -
Build
pokemonsay:EMBED_DB_PATH="$(realpath ./pokeapi/db.sqlite3)" \ EMBED_SPRITES_PATH="$(realpath ./pokeapi/data/v2/sprites/sprites)" \ cargo build --release --features embed-db,embed-sprites
pokemonsay provides two compile-time features that control what assets are
embedded in the binary:
- What it does: Embeds the PokeAPI SQLite database directly into the compiled binary
- Default: Enabled
- Trade-offs:
- โ Queries are faster (no disk I/O)
- โ No need to distribute a separate database file
- โ No rate limiting from PokeAPI (independent of HTTP queries)
- โ Increases binary size
When enabled, you can still use --query-method http to query PokeAPI instead,
or --db-path to specify an external database.
- What it does: Embeds all Pokemon sprite images into the binary
- Default: Disabled
- Trade-offs:
- โ Sprite retrieval is instant (no network requests)
- โ Works offline
- โ
--sprites-retrieval-method embeddedis available - โ Increases binary size
When enabled, you can still use --sprites-retrieval-method http to download
sprites instead.
Fastest, largest binary (full embedding):
cargo build --release --features embed-db,embed-spritesBalanced (embedded database, HTTP sprites):
cargo build --release --features embed-dbSmallest binary (requires runtime setup):
cargo build --release --no-default-featuresDefaults to using HTTP calls to PokeAPI.
Optionally, provide database and sprites at runtime:
pokemonsay --query-method db --db-path /path/to/pokeapi.dbLooking for the previous version written in JavaScript? Find it on the v1
branch.