Automatically generates and installs professional man pages from README.md files using Claude AI assistance. Transform your existing documentation into properly formatted man pages with a single command.
- Automatic Conversion: Transforms README.md files into properly formatted troff/man pages using Claude AI
- Smart Installation: Auto-detects installation context (user vs system-wide)
- Path Intelligence: Automatically finds README.md files in command directories
- Standard Compliance: Generates man pages following UNIX conventions with all standard sections
- Validation Support: Includes comprehensive test suite for man page validation
- Error Recovery: Robust error handling with informative messages
- Color Output: Terminal-aware colored output for better readability
Install with a single command:
# System-wide installation (recommended)
curl -sSL https://raw.githubusercontent.com/Open-Technology-Foundation/manpage/main/install.sh | sudo bash
# Or with wget
wget -qO- https://raw.githubusercontent.com/Open-Technology-Foundation/manpage/main/install.sh | sudo bash
# User-local installation (no sudo required)
curl -sSL https://raw.githubusercontent.com/Open-Technology-Foundation/manpage/main/install.sh | bash -s -- --userThis will install:
- The
manpagecommand to/usr/local/bin/(or~/.local/bin/for user install) - Bash completion support to
/etc/bash_completion.d/ - The man page to
/usr/local/share/man/man1/
# Clone the repository
git clone https://github.com/Open-Technology-Foundation/manpage.git
cd manpage
# Make executable
chmod +x manpage
# Generate and install manpage's own man page (user-local)
./manpage generate -i manpage
# Or install system-wide
sudo ./manpage generate -i manpage# System-wide uninstall
curl -sSL https://raw.githubusercontent.com/Open-Technology-Foundation/manpage/main/install.sh | sudo bash -s -- --uninstall
# User-local uninstall
curl -sSL https://raw.githubusercontent.com/Open-Technology-Foundation/manpage/main/install.sh | bash -s -- --uninstall --user# Generate a man page for your script
manpage generate ./myscript
# Generate and install in one command
manpage generate -i ./myscript
# View the generated man page
man myscriptmanpage [options] <command> [arguments]
manpage generate [-i|--install] <command> [<readme>]Converts a README.md file to a properly formatted man page using Claude AI.
Arguments:
<command>: Path to the command/script to document (required)<readme>: Optional path to README.md file (defaults to command's directory)
Options:
-i, --install: Install the man page immediately after generation
Behavior:
- Resolves full paths using
readlink -enfor reliability - Searches for README.md in the command's directory if not specified
- Generates
.1file in the same directory as the README - Validates output by checking for
.THdirective - Exits with error if README.md not found or generation fails
Output:
- Creates
<command>.1man page file - Displays success message with file path
- Shows warnings for validation issues
manpage install <command>Installs a previously generated man page to the appropriate directory.
Arguments:
<command>: Path to the command whose man page to install
Installation Locations:
- System-wide:
/usr/local/share/man/man1/(when running as root/sudo) - User-local:
~/.local/share/man/man1/(for regular users)
Behavior:
- Auto-detects root/sudo context for installation type
- Creates destination directories if needed
- Updates man database (
mandbormakewhatis) - Checks MANPATH configuration for user installations
- Sets appropriate file permissions (644)
-h, --help: Display help message and exit-v, --verbose: Enable verbose output (default)-q, --quiet: Disable verbose output-V, --version: Show version information
# Generate man page for a script in current directory
manpage generate ./myscript
# Generate for a system command
manpage generate /usr/local/bin/mytool
# Generate with explicit README location
manpage generate mytool ~/projects/mytool/docs/README.md
# Generate and install immediately
manpage generate -i ./myscript# Install for current user
manpage install ./myscript
# Install system-wide
sudo manpage install ./myscript
# Quiet mode installation
manpage -q install ./myscript# Generate man page for a symlinked command
manpage generate $(which mycommand)
# Generate from a specific branch's README
git show feature-branch:README.md > /tmp/README.md
manpage generate mycommand /tmp/README.md
# Batch processing
for script in scripts/*.sh; do
manpage generate -i "$script"
doneThe manpage utility follows a clean, modular architecture:
-
Path Resolution Layer
- Uses
readlink -enfor reliable path resolution - Handles symlinks, relative paths, and special characters
- Falls back to alternative resolution methods if needed
- Uses
-
README Discovery Engine
- Intelligent search algorithm for locating README.md files
- Checks command directory first, then accepts explicit paths
- Validates file existence before processing
-
AI Conversion Pipeline
- Constructs optimized prompts for Claude AI
- Specifies troff formatting directives and man page structure
- Includes all standard man page sections in proper order
- Handles complex markdown formatting conversions
-
Man Page Generation
- Creates section 1 (user commands) man pages
- Validates output with
.THdirective checks - Stores generated files alongside source README
- Preserves original documentation structure
-
Smart Installation System
- Auto-detects execution context (root/sudo vs user)
- Creates necessary directory structures
- Sets proper file permissions (644)
- Updates man database for immediate availability
-
Error Handling Framework
- Comprehensive error checking at each step
- Informative error messages with exit codes
- Graceful fallback mechanisms
- Color-coded output for better visibility
-
claude: Claude CLI tool (required for AI conversion)
# Check if installed which claude || echo "Claude CLI not found"
-
bash: Version 4.0 or later
# Check version bash --version -
Standard UNIX utilities:
readlink- Path resolutiongrep- Pattern matchinginstall- File installationmandbormakewhatis- Man database updates
- groff: For rendering and testing man pages locally
- man: For viewing generated man pages
- shellcheck: For validating bash script syntax
Generated man pages follow the troff/groff format with standard sections:
.TH- Title header (name, section, date, version, manual)- NAME - Command name and one-line description
- SYNOPSIS - Usage syntax with options
- DESCRIPTION - Detailed explanation of functionality
- OPTIONS - Command-line flags and parameters
- EXAMPLES - Practical usage demonstrations
- EXIT STATUS - Return codes and their meanings
- ENVIRONMENT - Environment variables used
- FILES - Configuration files and paths
- NOTES - Additional important information
- BUGS - Known issues or bug reporting
- SEE ALSO - Related commands and documentation
- AUTHOR - Creator and maintainer information
- COPYRIGHT - License and legal notices
For user-local installations, ensure your MANPATH includes the local directory:
# Add to ~/.bashrc or ~/.zshrc
export MANPATH="$HOME/.local/share/man:$MANPATH"
# Verify MANPATH
manpath
# Rebuild man database
mandbThe script uses Claude with specific options:
- Model: Opus (configurable in script)
- Flags:
-p --dangerously-skip-permissions - Purpose: Bypasses interactive prompts for automation
- Generated man pages:
<readme_dir>/<command>.1 - User installation:
~/.local/share/man/man1/ - System installation:
/usr/local/share/man/man1/ - Man database: Updated via
mandbormakewhatis
The Claude CLI tool is required for AI conversion:
# Check if claude is installed
which claude
# Install instructions available at:
# https://github.com/anthropics/claude-cliThe script searches for README.md in the command's directory:
# Check if README exists
ls -la /path/to/command/README.md
# Specify README path explicitly
manpage generate mycommand /custom/path/README.mdFor user installations, verify MANPATH configuration:
# Check current MANPATH
manpath
# Add local man directory
echo 'export MANPATH="$HOME/.local/share/man:$MANPATH"' >> ~/.bashrc
source ~/.bashrc
# Rebuild database
mandb# For system installation, use sudo
sudo manpage install mycommand
# Check file permissions
ls -la ~/.local/share/man/man1/# Validate generated man page
groff -man -T ascii mycommand.1 > /dev/null
# Check for .TH directive
head -n 1 mycommand.1# Enable verbose mode for detailed output
manpage -v generate mycommand
# Check generated file before installation
less mycommand.1
# Test man page rendering
man -l mycommand.1
# Verify installation location
find /usr/local/share/man ~/.local/share/man -name "mycommand.1" 2>/dev/nullThe project includes a comprehensive test framework:
# Run complete test suite
./test/test_manpage.sh
# Run with verbose output
./test/test_manpage.sh -v
# Validate specific man page
./test/validate_man.sh mycommand.1
# Validate with detailed output
./test/validate_man.sh -v mycommand.1The test suite validates:
-
Core Functionality
- Man page generation from README
- Installation to user and system directories
- Path resolution and discovery
-
Edge Cases
- Paths with spaces and special characters
- Symlinks and relative paths
- Missing or invalid README files
- Non-existent commands
-
Man Page Validation
- Proper troff/groff syntax
- Required sections presence
- Format compliance
- Rendering without errors
-
Error Handling
- Missing dependencies
- Permission issues
- Invalid arguments
- Claude CLI failures
# Quick validation
shellcheck -x manpage
# Full test run
cd test && ./test_manpage.sh
# Specific test category
./test/test_manpage.sh --category=generationmanpage/
├── manpage # Main executable script
├── README.md # Project documentation (this file)
├── LICENSE # GPL-3 license file
├── test/ # Test suite directory
│ ├── test_manpage.sh # Comprehensive test runner
│ ├── validate_man.sh # Man page format validator
│ └── fixtures/ # Test data and examples
│ ├── sample.md # Example README files
│ └── expected/ # Expected output files
└── manpage.1 # Generated man page for manpage itself
-
Fork and Clone
git clone https://github.com/yourusername/manpage.git cd manpage -
Create Feature Branch
git checkout -b feature/your-feature
-
Make Changes
- Follow BASH-CODING-STANDARD
- Maintain 2-space indentation
- Use
set -euo pipefailfor error handling - Document new features in README
-
Test Thoroughly
# Syntax check shellcheck -x manpage # Run test suite ./test/test_manpage.sh # Test your changes ./manpage generate -i testscript
-
Submit Pull Request
- Clear description of changes
- Reference any related issues
- Include test results
- Bash Version: Target bash 4.0+ compatibility
- Error Handling: Use proper exit codes and error messages
- Functions: Prefix internal functions with underscore
- Variables: Use uppercase for globals, lowercase for locals
- Comments: Document complex logic and non-obvious code
- Add tests for new features
- Update existing tests when modifying behavior
- Ensure 100% pass rate before submitting PR
- Include edge cases and error conditions
The command-line interface is considered stable. Any breaking changes will:
- Be documented in CHANGELOG
- Increment major version number
- Provide migration guide
- Update version in script header
- Update README.md version reference
- Generate new man page
- Create git tag
- Push to repository
- Documentation: Read this README and generated man pages
- Issues: GitHub Issues
- Discussions: GitHub Discussions
When reporting issues, please include:
- Operating system and version
- Bash version (
bash --version) - Claude CLI version
- Complete error output
- Steps to reproduce
This project is licensed under the GNU General Public License v3.0 (GPL-3).
Key points:
- Free to use, modify, and distribute
- Source code must remain open
- Modifications must use same license
- No warranty provided
See LICENSE file for full details.
Created and maintained by the Indonesian Open Technology Foundation for automating man page generation from existing documentation.