# fortune-rs 🎲 [![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg)](https://www.rust-lang.org) [![Crates.io](https://img.shields.io/crates/v/fortune-rs.svg)](https://crates.io/crates/fortune-rs) [![Documentation](https://docs.rs/fortune-rs/badge.svg)](https://docs.rs/fortune-rs) [![build](https://github.com/twang2218/fortune-rs/actions/workflows/build.yml/badge.svg)](https://github.com/twang2218/fortune-rs/actions/workflows/build.yml) [![codecov](https://codecov.io/gh/twang2218/fortune-rs/branch/main/graph/badge.svg)](https://codecov.io/gh/twang2218/fortune-rs) [![dependency status](https://deps.rs/repo/github/twang2218/fortune-rs/status.svg)](https://deps.rs/repo/github/twang2218/fortune-rs) [![MSRV](https://img.shields.io/badge/MSRV-1.70.0-blue)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) > A modern, feature-rich implementation of the classic BSD `fortune` program in Rust. This implementation aims to be a drop-in replacement for traditional `fortune` programs on Unix-like systems while maintaining compatibility with various fortune database formats. ## πŸ“‘ Table of Contents - [fortune-rs 🎲](#fortune-rs-) - [πŸ“‘ Table of Contents](#-table-of-contents) - [✨ Features](#-features) - [πŸ“₯ Installation](#-installation) - [From Source](#from-source) - [πŸš€ Usage](#-usage) - [Basic Usage](#basic-usage) - [Common Options](#common-options) - [Advanced Usage](#advanced-usage) - [πŸ›  Development](#-development) - [Project Structure](#project-structure) - [Building](#building) - [Testing](#testing) - [Test Coverage](#test-coverage) - [πŸ”§ Implementation Details](#-implementation-details) - [πŸ—Ί Roadmap](#-roadmap) - [Current Status](#current-status) - [Future Plans](#future-plans) - [πŸ‘₯ Contributing](#-contributing) - [πŸ“„ License](#-license) - [πŸ“š References](#-references) - [Rust Implementations](#rust-implementations) ## ✨ Features - πŸ”„ Full compatibility with traditional fortune program options - πŸ“š Support for multiple fortune database formats - πŸ” Pattern matching with regular expressions - πŸ“Š Weighted fortune selection - 🌳 Recursive directory searching - πŸ“ Precise control over fortune length - 🎨 Support for both regular and offensive fortunes - πŸ› Debug output for troubleshooting ## πŸ“₯ Installation ### From Source ```bash # Clone the repository git clone https://github.com/twang2218/fortune-rs.git # Change into the directory cd fortune-rs # Build with optimizations cargo build --release ``` > The compiled binary will be available at `target/release/fortune` ## πŸš€ Usage ### Basic Usage ```bash # Display a random fortune fortune # Display a random fortune from specific files or directories fortune /path/to/fortune/file # Display a random offensive fortune fortune -o ``` ### Common Options | Option | Description | |--------|-------------| | `-a` | Choose from all lists of maxims | | `-c` | Show the cookie file source | | `-f` | Print out the list of files | | `-o` | Choose only offensive fortunes | | `-s` | Display short fortunes only | | `-l` | Display long fortunes only | | `-n length` | Set length cutoff | | `-m pattern` | Display matching fortunes | | `-i` | Ignore case in pattern matching | | `-w` | Wait based on message length | | `-e` | Equal size file handling | | `-D` | Enable debugging output | ### Advanced Usage ```bash # Pattern matching (case-insensitive) fortune -i -m "pattern" # Short fortunes only fortune -s # Show fortune sources fortune -c # List available fortune files fortune -f # Weighted selection fortune 30% /path/to/fortunes1 70% /path/to/fortunes2 ``` ## πŸ›  Development ### Project Structure ``` fortune-rs/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ fortune.rs # Main implementation β”‚ β”œβ”€β”€ strfile.rs # Database generator β”‚ └── metadata.rs # Metadata handling β”œβ”€β”€ tests/ β”‚ β”œβ”€β”€ integration.rs # Integration tests β”‚ β”œβ”€β”€ data/ # Test files β”‚ └── data2/ # Additional tests └── Cargo.toml # Project manifest ``` ### Building ```bash # Debug build cargo build # Release build with optimizations cargo build --release ``` ### Testing ```bash # Run all tests cargo test ``` #### Test Coverage - βœ… Pattern matching (`-m`) - βœ… Case-insensitive search (`-i`) - βœ… Length-based filtering (`-l`, `-s`, `-n`) - βœ… File listing (`-f`) - βœ… Weighted selection - βœ… Offensive fortunes (`-o`) - βœ… Equal-size handling (`-e`) ## πŸ”§ Implementation Details - βœ… Compatible with traditional fortune database formats - βœ… Supports regular and offensive fortunes - βœ… Implements weighted selection - βœ… Pattern matching with regex - βœ… Recursive directory traversal - βœ… Multiple file formats and encodings - βœ… Strfile index compatibility ## πŸ—Ί Roadmap ### Current Status - βœ… Core Functionality - βœ… Random fortune display - βœ… Strfile index support - βœ… Directory searching - βœ… Traditional Options - βœ… Standard flags - βœ… Pattern matching - βœ… Length control - βœ… Debug output ### Future Plans - πŸ”„ Modern Enhancements - ⏳ TOML configuration - ⏳ Embedded fortune database - πŸ“ˆ Project Growth - ⏳ Extended docs - βœ… Comprehensive testing - ⏳ CI/CD pipeline ## πŸ‘₯ Contributing We welcome contributions! Here's how you can help: 1. 🍴 [Fork](https://github.com/twang2218/fortune-rs/fork) the repository 2. 🌿 [Create a branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository) for your feature 3. βœ… [Add tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) for new features 4. πŸ§ͺ [Ensure all tests pass](https://doc.rust-lang.org/book/ch11-00-testing.html) 5. πŸ“¬ [Submit a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) ## πŸ“„ License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## πŸ“š References ### Rust Implementations - [cmatsuoka/fortune-rs](https://github.com/cmatsuoka/fortune-rs), by Claudio Matsuoka, Brazil, at 2017; - [c-OO-b/rust-fortune](https://github.com/c-OO-b/rust-fortune), by c-OO-b, Norway, at 2019; - [wapm-packages/fortune](https://wapm.io/package/fortune), forked from [c-OO-b/rust-fortune](https://github.com/c-OO-b/rust-fortune), at 2019; - [runebaas/fortune-mod.rs](https://github.com/runebaas/fortune-mod.rs), by [Daan Boerlage](https://boerlage.me), Switzerland, at 2019; - [kvrohit/fortune](https://github.com/kvrohit/fortune), by [Rohit K Viswanath](https://kvrohit.dev/), at 2020; - [davidkna/lolcow-fortune-rs](https://github.com/davidkna/lolcow-fortune-rs.git), by David Knaack, Berlin, Germany, at 2021; - [blackbird1128/fortune_cookie](https://github.com/blackbird1128/fortune_cookie.rs.git), by Alexj, at 2023; - [zuisong/rs-fortune](https://github.com/zuisong/rs-fortune), by ZuiSong, Changsha, China, at 2023; - [cafkafk/fortune-kind](https://github.com/cafkafk/fortune-kind), by [Christina SΓΈrensen](https://www.linkedin.com/in/cafkafk/), Denmark, at 2023; - [rilysh/fortune-day](https://github.com/rilysh/fortune-day.git), at 2024; - [FaceFTW/shell-toy](https://github.com/FaceFTW/shell-toy.git), by [Alex Westerman](http://faceftw.dev/), at 2024;