1 unstable release
new 0.1.0 | Nov 26, 2024 |
---|
#126 in Text processing
57KB
1K
SLoC
fortune-rs π²
A modern, feature-rich implementation of the classic BSD
fortune
program in Rust. This implementation aims to be a drop-in replacement for traditionalfortune
programs on Unix-like systems while maintaining compatibility with various fortune database formats.
π Table of Contents
- fortune-rs π²
β¨ 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
# 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
# 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
# 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
# Debug build
cargo build
# Release build with optimizations
cargo build --release
Testing
# 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:
- π΄ Fork the repository
- πΏ Create a branch for your feature
- β Add tests for new features
- π§ͺ Ensure all tests pass
- π¬ Submit a pull request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π References
Rust Implementations
- cmatsuoka/fortune-rs, by Claudio Matsuoka, Brazil, at 2017;
- c-OO-b/rust-fortune, by c-OO-b, Norway, at 2019;
- wapm-packages/fortune, forked from c-OO-b/rust-fortune, at 2019;
- runebaas/fortune-mod.rs, by Daan Boerlage, Switzerland, at 2019;
- kvrohit/fortune, by Rohit K Viswanath, at 2020;
- davidkna/lolcow-fortune-rs, by David Knaack, Berlin, Germany, at 2021;
- blackbird1128/fortune_cookie, by Alexj, at 2023;
- zuisong/rs-fortune, by ZuiSong, Changsha, China, at 2023;
- cafkafk/fortune-kind, by Christina SΓΈrensen, Denmark, at 2023;
- rilysh/fortune-day, at 2024;
- FaceFTW/shell-toy, by Alex Westerman, at 2024;
Dependencies
~4β5.5MB
~99K SLoC