PT - Production-hardened Clipboard to File Tool
A robust command-line tool for managing clipboard content with intelligent file versioning, backup management, and recursive search capabilities.
🚀 Features
Core Functionality
- ✅ Clipboard to File - Save clipboard content to files instantly
- ✅ Smart Backup System - Automatic versioning with timestamps and comments
- ✅ Recursive File Search - Find files anywhere in subdirectories
- ✅ Check Mode - Skip writes when content is identical (save disk space)
- ✅ Append Mode - Add clipboard content to existing files
- ✅ Comment Support - Add descriptive comments to all operations
Advanced Features
- 🌳 Directory Tree View - Visualize directory structure with gitignore support
- 📦 Backup Management - List, restore, and compare backup versions
- 🔍 Delta Integration - Beautiful side-by-side diffs using delta CLI
- 🗑️ Safe Deletion - Backup files before deletion with empty placeholder
- ⚙️ Configuration System - Customize behavior via YAML config
- 📊 Metadata Storage - Track backup comments, timestamps, and origins
Security & Validation
- 🔒 Path traversal protection
- 🔒 System directory write protection
- 🔒 File size limits (configurable, default 100MB)
- 🔒 Filename length validation
- 🔒 Disk space checking
📦 Installation
From Source
# Clone repository
# Build release binary
# Binary will be at: target/release/pt
# Optional: Install to system
From Crates.io (when published)
🎯 Quick Start
# Write clipboard to file
# Write with check mode (skip if identical)
# Write with comment
# Append clipboard to file
# List all backups
# Restore from backup (interactive)
# Restore last backup
# Compare with backup using delta
# Show directory tree
# Configuration
# Version info
📖 Command Reference
Write Operations
# Basic write
Append Mode
Backup Management
File Operations
Directory Tree
Configuration
⚙️ Configuration
Create a pt.yml file in one of these locations:
./pt.yml(current directory)~/.config/pt/pt.yml~/pt.yml
Sample Configuration
# PT Configuration File
# Maximum clipboard content size in bytes (default: 104857600 = 100MB)
max_clipboard_size: 104857600
# Maximum number of backups to keep (default: 100)
max_backup_count: 100
# Maximum filename length (default: 200)
max_filename_length: 200
# Backup directory name (default: "backup")
backup_dir_name: backup
# Maximum directory depth for recursive search (default: 10)
max_search_depth: 10
Generate sample config:
📂 Backup System
Backup Location
All backups are stored in the ./backup/ directory (configurable).
Backup Naming
Format: {filename}_{ext}.{timestamp}.{pid}_{random}
Example: notes_txt.20241115_143022123456.12345_a3f4
Backup Metadata
Each backup includes a .meta.json file containing:
🔍 Recursive Search
When a file is not found in the current directory, PT automatically searches subdirectories (up to configured depth).
# File in subdirectory
# If multiple files found, interactive selection:
)
)
🎨 Delta Integration
PT supports delta for beautiful diffs:
# Install delta
# Use with PT
Features:
- Syntax highlighting
- Line numbers
- Side-by-side or unified diff
- Customizable themes
🌳 Tree View
Display directory structure with file sizes:
)
)
)
)
Gitignore Support
Tree view respects .gitignore patterns automatically.
Exceptions
Exclude specific files/directories:
🔒 Security Features
-
Path Validation
- Blocks path traversal (
..) - Prevents system directory writes
- Filename length limits
- Blocks path traversal (
-
Size Limits
- Configurable max clipboard size
- File size validation before operations
-
Backup Limits
- Automatic cleanup of old backups
- Configurable retention count
🚦 Exit Codes
0- Success1- Error (with descriptive message)
🐛 Troubleshooting
Clipboard Access Issues
Linux: Install xclip or xsel
# or
macOS: Should work out of the box
Windows: Should work out of the box
Delta Not Found
Install delta for diff functionality:
Permission Denied
Check write permissions:
📊 Examples
Daily Workflow
# Morning: Start notes
# Throughout day: Append updates
# Review changes
# If needed, restore previous version
# End of day: Archive
Code Snippets
# Quick code snippet storage
# Later: Review and compare
Project Documentation
# Save clipboard content to docs
# Tree view of docs
# Restore if needed
🤝 Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Hadi Cahyadi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
💻 Author
- GitHub: @cumulus13
- Email: cumulus13@gmail.com
Made with ❤️ by Hadi Cahyadi
Your complete file version management system with contextual history in a single command. ⚡
If you find PT useful, consider supporting its development and please consider giving it a star on GitHub! ⭐:
🙏 Acknowledgments
- clipboard - Clipboard access
- clap - CLI argument parsing
- delta - Beautiful diffs
- walkdir - Directory traversal
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
