Skip to content

cumulus13/pt-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

48 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‹ pt – Clipboard to File Tool with Smart Version Management

Go Version License Version

pt is a powerful CLI tool that writes your clipboard content directly to a file – with automatic timestamped backups, backup comments, recursive file search, delta diff comparison, directory tree visualization, and safe file deletion. It's not just a clipboard manager – it's a complete version control system for your files!

✨ Features

Core Features

  • πŸ“ Quick Save - Write clipboard content to file with one command
  • πŸ“¦ Auto Backup - Automatic timestamped backups stored in ./backup/ directory
  • πŸ’¬ Backup Comments - Add descriptive comments to track why changes were made ✨ NEW!
  • βž• Append Mode - Add content without creating backups
  • πŸ”„ Restore - Interactive or quick restore from backups with comments
  • πŸ“Š Beautiful Listings - Formatted table view of all backups with sizes and comments ✨ NEW!
  • πŸ”’ Production Hardened - Path validation, size limits, error handling
  • 🎨 Colorful Output - ANSI colors for better readability
  • πŸ“ˆ Audit Logging - All operations logged for tracking
  • βœ… Check Mode - Skip writes if content unchanged (saves disk space) ✨ NEW!

Advanced Features

  • πŸ” Recursive File Search - Automatically finds files in subdirectories up to 10 levels deep
  • πŸ“Š Delta Diff Integration - Beautiful side-by-side diff comparison with backups
  • 🌳 Directory Tree View - Visual file structure with sizes (like tree command)
  • πŸ“ GitIgnore Support - Respects .gitignore patterns in tree view
  • πŸ—‘οΈ Safe Delete - Backup before deletion, create empty placeholder
  • βš™οΈ Exception Filtering - Exclude specific files/folders from tree view
  • 🎯 Multi-File Selection - Interactive prompt when multiple files found
  • πŸš€ Smart Path Resolution - Finds files anywhere in your project
  • βš™οΈ Configurable - Customize behavior via pt.yml config file ✨ NEW!

Version Management Capabilities with Comments ✨ NEW!

PT acts as a lightweight version control system with descriptive comments:

  • πŸ“œ Complete Version History - Every file change is preserved with optional comments
  • πŸ’¬ Comment System - Track why changes were made, not just when
  • πŸ“ Contextual Notes - Add meaningful descriptions to each backup
  • πŸ”™ Easy Rollback - Restore any previous version instantly, see why it was saved
  • πŸ“Š Version Comparison - Diff any two versions visually with delta
  • 🎯 Zero Data Loss - Never lose work, automatic backup before every write
  • πŸ’Ύ Space Efficient - Only changed files are backed up
  • 🏷️ Timestamped Versions - Microsecond precision timestamps + human-readable comments

πŸš€ Installation

Prerequisites

  • Go 1.16 or higher
  • Git (for installation)
  • Delta (optional, for diff functionality) - Install from here

Install from Source

go install github.com/cumulus13/pt-go/pt@latest

# or Clone the repository
git clone https://github.com/cumulus13/pt-go.git
cd pt-go

# Build and install
go build -o pt pt/main.go

# Move to your PATH (Linux/macOS)
sudo mv pt /usr/local/bin/

# Or for Windows, add to your PATH manually

Quick Install (Linux/macOS)

# One-liner installation
curl -sSL https://raw.githubusercontent.com/cumulus13/pt-go/pt/main/install.sh | bash

Install Delta (for diff feature)

# macOS
brew install git-delta

# Ubuntu/Debian
sudo apt install git-delta

# Arch Linux
sudo pacman -S git-delta

# Fedora/RHEL
sudo dnf install git-delta

# Windows (with Chocolatey)
choco install delta

# Windows (with Scoop)
scoop install delta

# Or download from: https://github.com/dandavison/delta/releases

Verify Installation

pt --version
# PT version 1.0.19
# Production-hardened clipboard to file tool
# Features: Recursive search, backup management, delta diff, tree view, safe delete, configurable, comments

[Documentation] (https://pt.readthedocs.io/en/latest)

πŸ“– Usage

Basic Commands

# Write clipboard to file (creates backup if exists)
pt myfile.txt

# Write with comment ✨ NEW!
pt myfile.txt -m "Fixed bug in authentication logic"

# Write with check mode (skip if unchanged) ✨ NEW!
pt myfile.txt -c

# Combine check mode with comment ✨ NEW!
pt myfile.txt -c -m "Updated configuration"

# Append clipboard to file (no backup)
pt + myfile.txt

# Append with comment ✨ NEW!
pt + myfile.txt -m "Added new log entry"

# List all backups with sizes, timestamps, and comments ✨ NEW!
pt -l myfile.txt

# Restore backup (interactive selection)
pt -r myfile.txt

# Restore with comment ✨ NEW!
pt -r myfile.txt -m "Rolled back to stable version"

# Restore last backup directly
pt -r myfile.txt --last

# Restore last backup with comment ✨ NEW!
pt -r myfile.txt --last -m "Emergency rollback"

# Show help
pt --help

# Show version
pt --version

Configuration Commands

# Initialize configuration file
pt config init              # Creates pt.yml in current directory
pt config init ~/.pt.yml    # Create in custom location

# Show current configuration
pt config show

# Show config file location
pt config path

Advanced Commands

# πŸ” RECURSIVE SEARCH - Automatically finds files in subdirectories
pt config.json              # Searches up to 10 levels deep
pt -l utils.go              # List backups (searches recursively)
pt -r main.py               # Restore (searches recursively)

# πŸ“Š DIFF OPERATIONS - Compare with backups using delta
pt -d myfile.txt            # Interactive: choose which backup to compare
pt -d myfile.txt --last     # Quick: compare with most recent backup
pt --diff script.py         # Alternative syntax

# 🌳 DIRECTORY TREE - Visualize file structure
pt -t                       # Show tree of current directory
pt -t /path/to/dir          # Show tree of specific directory
pt -t -e node_modules,.git  # Tree with exceptions (exclude folders)
pt -t /path -e build,dist   # Combine path and exceptions

# πŸ—‘οΈ SAFE DELETE - Backup before deletion
pt -rm old_file.txt         # Backup, delete, create empty placeholder
pt -rm old_file.txt -m "Deprecated old implementation"  # With comment ✨ NEW!
pt --remove script.py       # Alternative syntax

πŸ“š Examples

1. Quick Note Taking with Comments ✨ NEW!

# Copy some text to clipboard, then:
pt notes.txt -m "Meeting notes from sprint planning"
# βœ… Successfully written to: notes.txt
# πŸ“„ Content size: 142 characters
# πŸ’¬ Comment: "Meeting notes from sprint planning"

2. Version Control for Code Changes ✨ NEW!

# Before making risky changes
pt main.go -m "Working version before refactoring"
# πŸ“¦ Backup created: main_go.20251118_141241...
# πŸ’¬ Comment: "Working version before refactoring"

# After changes (only saves if different)
pt main.go -c -m "Refactored authentication module"
# πŸ” Content differs, proceeding with backup and write
# βœ… Successfully written to: main.go

# View version history with comments
pt -l main.go
# Shows table with comments for each version

3. Configuration Management with Context ✨ NEW!

# Save production config
pt config.json -m "Production config for v2.1.0 release"

# Later, update for testing
pt config.json -m "Testing new cache settings"

# View all config versions with comments
pt -l config.json
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ File Name  β”‚ Modified    β”‚ Size β”‚ Comment                    β”‚
# β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
# β”‚ 1. config..β”‚ 14:12:41    β”‚ 2 KB β”‚ Testing new cache settings β”‚
# β”‚ 2. config..β”‚ 10:30:15    β”‚ 2 KB β”‚ Production config v2.1.0   β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

# Restore production config
pt -r config.json -m "Reverting to production config"

4. Check Mode - Save Disk Space ✨ NEW!

# Only write if content actually changed
pt data.json -c
# ℹ️  Content identical to current file, no changes needed
# πŸ“„ File: data.json

# Or with comment if it does change
pt data.json -c -m "Updated user preferences"
# πŸ” Content differs, proceeding with backup and write
# πŸ“¦ Backup created with comment

5. Safe Delete with Context ✨ NEW!

# Delete old implementation with explanation
pt -rm legacy_auth.py -m "Replaced by new OAuth2 implementation"
# πŸ“¦ Backup created: legacy_auth_py.20251118_141241...
# πŸ’¬ Comment: "Replaced by new OAuth2 implementation"
# πŸ—‘οΈ  File deleted: legacy_auth.py
# πŸ“„ Created empty placeholder: legacy_auth.py

6. Append Mode with Comments ✨ NEW!

# Append log entries with context
pt + errors.log -m "Error logs from production incident"
# βœ… Successfully appended to: errors.log
# πŸ“ Content size: 87 characters
# πŸ’¬ Comment: "Error logs from production incident"

7. Interactive Restore with Comment History ✨ NEW!

pt -r main.go

# πŸ“‚ Backup files for 'main.go'
# Total: 5 backup(s) (stored in ./backup/)
# 
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ File Name                β”‚ Modified            β”‚     Size β”‚ Comment                        β”‚
# β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
# β”‚ 1. main_go.20251118...   β”‚ 2025-11-18 14:12:41 β”‚  50.5 KB β”‚ Add comment system             β”‚
# β”‚ 2. main_go.20251118...   β”‚ 2025-11-18 14:11:24 β”‚  57.0 KB β”‚ Working version before refactorβ”‚
# β”‚ 3. main_go.20251118...   β”‚ 2025-11-18 13:43:01 β”‚  52.6 KB β”‚ Fixed authentication bug       β”‚
# β”‚ 4. main_go.20251113...   β”‚ 2025-11-13 11:47:02 β”‚  49.2 KB β”‚ -                              β”‚
# β”‚ 5. main_go.20251113...   β”‚ 2025-11-13 11:39:49 β”‚  49.2 KB β”‚ -                              β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
# 
# Enter backup number to restore (1-5) or 0 to cancel: 2
# βœ… Successfully restored: main.go
# πŸ“¦ From backup: main_go.20251118_141124...
# πŸ’¬ Restore comment: "Restored from backup"

8. Configuration File ✨ NEW!

# Create configuration file
pt config init

# Edit pt.yml
cat > pt.yml << EOF
# PT Configuration File
max_clipboard_size: 104857600    # 100MB
max_backup_count: 100            # Keep 100 backups
max_filename_length: 200         # Max filename length
backup_dir_name: backup          # Backup directory name
max_search_depth: 10             # Max recursive search depth
EOF

# View current config
pt config show
# 
# Current PT Configuration:
# 
# Max Clipboard Size: 104857600 bytes (100.0 MB)
# Max Backup Count: 100
# Max Filename Length: 200 characters
# Backup Directory: backup/
# Max Search Depth: 10 levels
# 
# Config loaded from: ./pt.yml

9. Recursive File Search

# File not in current directory? PT finds it automatically!
pt config.json
# πŸ” Searching for 'config.json' recursively...
# βœ“ Found at: /path/to/project/src/config.json

# Multiple files found? PT shows interactive selection
pt README.md
# πŸ” Found 3 matching file(s)
# 
# β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚   #  β”‚ Path                       β”‚ Modified            β”‚ Size         β”‚
# β”œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
# β”‚    1 β”‚ ./README.md                β”‚ 2025-11-15 10:30:00 β”‚ 15.2 KB      β”‚
# β”‚    2 β”‚ ./docs/README.md           β”‚ 2025-11-14 15:20:00 β”‚ 8.5 KB       β”‚
# β”‚    3 β”‚ ./examples/README.md       β”‚ 2025-11-13 09:15:00 β”‚ 3.2 KB       β”‚
# β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
# 
# Enter file number to use (1-3) or 0 to cancel: 1
# βœ“ Using: ./README.md

10. Visual Diff Comparison

# Interactive diff - choose which backup to compare
pt -d main.go
# πŸ“‚ Backup files for 'main.go'
# [Shows list of backups with comments]
# Enter backup number to compare (1-5) or 0 to cancel: 1
# πŸ“Š Comparing with backup: main_go.20251115_120000...
# [Beautiful side-by-side diff powered by delta]

# Quick diff with last backup
pt -d main.go --last
# πŸ“Š Comparing with last backup: main_go.20251115_151804...
# Current file: /path/to/main.go
# Backup file:  /path/to/backup/main_go.20251115_151804...
# [Beautiful colored diff output]

11. Directory Tree Visualization

# Show current directory tree
pt -t
# myproject/
# β”œβ”€β”€ src/
# β”‚   β”œβ”€β”€ main.go (15.2 KB)
# β”‚   └── utils.go (3.4 KB)
# β”œβ”€β”€ backup/
# β”‚   └── main_go.20251115_101530.12345 (8.1 KB)
# β”œβ”€β”€ README.md (2.1 KB)
# └── go.mod (456 B)
# 
# 2 directories, 5 files, 29.2 KB total

# Exclude specific folders
pt -t -e node_modules,.git,dist

🎨 Output Examples

Backup Listing with Comments ✨ NEW!

πŸ“‚ Backup files for 'myfile.txt'
Total: 5 backup(s) (stored in ./backup/)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ File Name                            β”‚ Modified            β”‚         Size β”‚ Comment                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. myfile_txt.20251118_141241...     β”‚ 2025-11-18 14:12:41 β”‚      2.45 KB β”‚ Add comment system                   β”‚
β”‚ 2. myfile_txt.20251118_140030...     β”‚ 2025-11-18 14:00:30 β”‚      2.40 KB β”‚ Fixed bug in auth logic              β”‚
β”‚ 3. myfile_txt.20251118_120000...     β”‚ 2025-11-18 12:00:00 β”‚      1.98 KB β”‚ Updated configuration                β”‚
β”‚ 4. myfile_txt.20251114_180000...     β”‚ 2025-11-14 18:00:00 β”‚      1.85 KB β”‚ -                                    β”‚
β”‚ 5. myfile_txt.20251114_100000...     β”‚ 2025-11-14 10:00:00 β”‚      1.52 KB β”‚ -                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Check Mode Output ✨ NEW!

# When content is identical
pt data.json -c
# ℹ️  Content identical to current file, no changes needed
# πŸ“„ File: data.json

# When content differs
pt data.json -c -m "Updated schema"
# πŸ” Content differs, proceeding with backup and write
# πŸ“¦ Backup created: data_json.20251118_141241...
# πŸ’¬ Comment: "Updated schema"
# βœ… Successfully written to: data.json

πŸ—‚οΈ Project Structure

pt/
β”œβ”€β”€ backup/                         # Auto-created backup directory
β”‚   β”œβ”€β”€ main_go.20251115_163913... # Timestamped backups
β”‚   β”œβ”€β”€ main_go.20251115_163913.....meta.json # Metadata with comments ✨ NEW!
β”‚   └── main_go.20251115_151804...
β”œβ”€β”€ go.mod                          # Go module definition
β”œβ”€β”€ go.sum                          # Dependency checksums
β”œβ”€β”€ pt/
β”‚   └── main.go                     # Main application code
β”œβ”€β”€ pt.yml                          # Configuration file (optional) ✨ NEW!
β”œβ”€β”€ README.md                       # This file
β”œβ”€β”€ LICENSE                         # MIT License
β”œβ”€β”€ VERSION                         # Version file
β”œβ”€β”€ .gitignore                      # Git ignore rules
└── install.sh                      # Installation script (optional)

Backup Metadata Format ✨ NEW!

All backups are stored in a ./backup/ subdirectory relative to the file location. Each backup now has an associated .meta.json file:

project/
β”œβ”€β”€ myfile.txt                      # Current version
β”œβ”€β”€ backup/                         # Backup directory (auto-created)
β”‚   β”œβ”€β”€ myfile_txt.20251115_151804... # Backup 1
β”‚   β”œβ”€β”€ myfile_txt.20251115_143022... # Backup 2
β”‚   └── myfile_txt.20251115_120000... # Backup 3
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js                      # Current version
β”‚   └── backup/                     # Separate backup dir per location
β”‚       └── app_js.20251115_120000...
└── other_files.txt
{
  "comment": "Fixed authentication bug",
  "timestamp": "2025-11-18T14:12:41.500000Z",
  "size": 51712,
  "original_file": "/path/to/main.go"
}

πŸ”§ Configuration

Configuration File (pt.yml) ✨ NEW!

PT now supports configuration via pt.yml file. Search locations (in order):

  1. ./pt.yml or ./pt.yaml (current directory)
  2. ~/.config/pt/pt.yml or ~/.config/pt/pt.yaml
  3. ~/pt.yml or ~/pt.yaml (home directory)

Create Config File

# Generate sample config
pt config init

# Or create manually
cat > pt.yml << EOF
# PT Configuration File
max_clipboard_size: 104857600    # 100MB (1-1GB)
max_backup_count: 100            # 100 backups (1-10000)
max_filename_length: 200         # 200 chars (1-1000)
backup_dir_name: backup          # "backup" directory
max_search_depth: 10             # 10 levels (1-100)
EOF

Configuration Options

Setting Default Range Description
max_clipboard_size 104857600 (100MB) 1 - 1073741824 (1GB) Maximum clipboard content size
max_backup_count 100 1 - 10000 Maximum backups kept per file
max_filename_length 200 1 - 1000 Maximum filename length
backup_dir_name backup - Backup directory name
max_search_depth 10 1 - 100 Recursive search depth

View Configuration

# Show current config
pt config show

# Show config file location
pt config path

Backup Naming Format

Backups use this format for zero-collision guarantee:

originalname_ext.YYYYMMDD_HHMMSS_MICROSECONDS.PID_RANDOMID

Example:

notes_txt.20251115_151804177132.12345_a1b2c3d4
notes_txt.20251115_151804177132.12345_a1b2c3d4.meta.json  ✨ NEW!

Components:

  • notes_txt - Original filename without extension
  • 20251115_151804177132 - Timestamp with microsecond precision
  • 12345 - Process ID
  • a1b2c3d4 - Random 8-character hex ID
  • .meta.json - Metadata file with comment ✨ NEW!

This ensures zero collision risk even with:

  • Multiple concurrent PT instances
  • Same-second operations
  • Parallel processing
  • Multiple files with same name in different directories

πŸ”’ Security Features

Path Validation

  • βœ… Prevents path traversal attacks (../../../etc/passwd)
  • βœ… Blocks writes to system directories (/etc, /sys, C:\Windows)
  • βœ… Validates filename length limits
  • βœ… Sanitizes all file paths
  • βœ… Validates recursive search depth
  • βœ… Validates configuration values ✨ NEW!

Size Limits

  • βœ… Maximum 100MB clipboard content (configurable) ✨ NEW!
  • βœ… Prevents disk exhaustion attacks
  • βœ… Validates disk space before writing
  • βœ… Checks write permissions

Input Validation

  • βœ… All user inputs sanitized
  • βœ… Numeric inputs validated for range
  • βœ… Graceful handling of malformed input
  • βœ… Protected against command injection
  • βœ… Safe file selection in multi-match scenarios
  • βœ… Configuration file validation ✨ NEW!

Safe Operations

  • βœ… Atomic-like file operations
  • βœ… Verification of write completion
  • βœ… Automatic rollback on errors
  • βœ… Backup before destructive operations
  • βœ… Backup directory exclusion from search
  • βœ… Metadata integrity checks ✨ NEW!

⚠️ Limitations

  1. Text Only - Only supports text content (no binary clipboard data)
  2. Single File - Operates on one file at a time
  3. Local Only - No network or cloud storage support
  4. Platform Support - Requires clipboard access (may need X11 on Linux headless)
  5. Delta Required - Diff feature requires delta to be installed
  6. Search Depth - Recursive search limited to configurable depth (default 10)
  7. Backup Exclusion - Configured backup directories excluded from search
  8. Comment Length - No enforced limit on comment length ✨ NEW!

πŸ›  Troubleshooting

Clipboard Empty Error

⚠️  Warning: Clipboard is empty

Solution: Copy some text to clipboard before running PT

No Write Permission

❌ Error: no write permission in directory

Solution: Check directory permissions or use a different location

File Too Large

❌ Error: clipboard content too large (max 100MB)

Solution: Content exceeds safety limit. Increase max_clipboard_size in config or save directly

File Not Found (NEW!)

❌ Error: file not found: config.json

Solutions:

  • Check filename spelling
  • File might be deeper than 10 levels (increase MaxSearchDepth)
  • Ensure file exists somewhere in the directory tree
  • Use absolute path if outside search scope

Config File Issues ✨ NEW!

⚠️  Warning: invalid max_clipboard_size, using default

Solution: Check config file syntax and value ranges. Use pt config show to verify

Content Unchanged (Check Mode) ✨ NEW!

ℹ️  Content identical to current file, no changes needed

This is normal: Check mode (-c) prevents unnecessary writes when content hasn't changed Solution: Select the file number you want to work with, or press 0 to cancel

Linux Clipboard Issues

❌ Error: failed to read clipboard

Solution: Install clipboard utilities:

# Ubuntu/Debian
sudo apt-get install xclip xsel

# Fedora/RHEL
sudo dnf install xclip xsel

# Arch
sudo pacman -S xclip xsel

Delta Not Found

❌ Error: delta not installed. Install it from: https://github.com/dandavison/delta

Solution: Install delta for diff functionality:

# macOS
brew install git-delta

# Ubuntu/Debian
sudo apt install git-delta

# Arch Linux
sudo pacman -S git-delta

# Windows
scoop install delta

Recursive Search Issues (NEW!)

πŸ” Searching for 'file.txt' recursively...
❌ Error: file not found: file.txt

Possible causes:

  • File is deeper than 10 directory levels
  • File is in a backup subdirectory (automatically excluded)
  • Permission issues reading some directories
  • Typo in filename

Solutions:

  • Use absolute path: pt /full/path/to/file.txt
  • Increase MaxSearchDepth in code
  • Check file permissions
  • Verify filename spelling

πŸ§ͺ Testing

Manual Testing

# Test basic write
echo "Hello World" | pbcopy  # macOS (or xclip -selection clipboard on Linux)
pt test.txt

# Test append
echo "Line 2" | pbcopy
pt + test.txt

# Test backup listing
pt -l test.txt

# Test restore
pt -r test.txt --last

# Test diff
pt -d test.txt --last

# Test recursive search (NEW!)
mkdir -p deep/nested/path
echo "test" | pbcopy
pt deep/nested/path/file.txt
cd ../../..
pt -l file.txt  # Should find it automatically

# Test multiple file selection (NEW!)
echo "test1" | pbcopy
pt test.txt
mkdir subdir
echo "test2" | pbcopy
pt subdir/test.txt
pt test.txt  # Should show selection prompt

# Test tree
pt -t

# Test safe delete
pt -rm test.txt

Run Tests (if implemented)

go test ./...

πŸ“Š Performance

Operation Performance Notes
Startup Time < 50ms Very fast startup
Write Speed Disk I/O limited Depends on storage
Memory Usage ~5MB + content Minimal footprint
Backup Creation < 100ms For typical files
Search Speed < 200ms For 1000+ files (NEW!)
Multi-file Search < 500ms Up to 10 levels deep (NEW!)
Tree Generation < 500ms For 5000+ files/folders
Diff Rendering Depends on delta Powered by delta

🎯 Use Cases

1. Version Control System with Context ✨ NEW!

Use PT as a lightweight version control with meaningful comments:

  • Track every change with why it was made
  • Compare versions visually with delta
  • Restore any previous version instantly
  • See the context of each change through comments
  • No git repository needed

2. Configuration Management with Audit Trail ✨ NEW!

Perfect for tracking config changes:

  • Document why each config change was made
  • Check mode prevents duplicate backups
  • Compare configurations visually
  • Easy rollback with context
  • Complete audit trail with comments

3. Code Snippet Library with Notes ✨ NEW!

Build your snippet collection with context:

  • Save snippets with descriptive comments
  • Version history with reasons for changes
  • Compare different versions
  • Organize with meaningful metadata

4. Documentation Workflow with Tracking ✨ NEW!

Better documentation management:

  • Track all changes with explanations
  • Visual diff of updates
  • Restore previous versions
  • Know why changes were made
  • Organized backup history with comments

5. Emergency Rollback with Context ✨ NEW!

Quick recovery with understanding:

  • Instant rollback to any version
  • See why each version was saved
  • Compare what changed
  • Document the rollback reason
  • Complete incident tracking

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone your fork
git clone https://github.com/cumulus13/pt-go.git
cd pt-go

# Install dependencies
go mod download

# Run in development
go run pt/main.go --help

# Build
go build -o pt pt/main.go

# Format code
go fmt ./...

# Run linters (optional)
golangci-lint run

Feature Ideas

Want to contribute? Here are some ideas:

  • Config file support (.ptrc) (βœ… DONE in v1.0.19)
  • Backup comments/metadata (βœ… DONE in v1.0.19)
  • Check mode to skip identical content (βœ… DONE in v1.0.19)
  • Custom backup directory location (absolute path)
  • Backup compression (gzip)
  • Backup to cloud storage (S3, GCS)
  • Web UI for backup management
  • Backup cleanup strategies (by age, size)
  • File watching mode (auto-backup on change)
  • Backup tags (additional metadata)
  • Multi-file operations
  • Backup encryption
  • Recursive file search (βœ… DONE in v1.0.25)
  • Delta diff integration (βœ… DONE in v1.0.25)
  • Interactive file selection (βœ… DONE in v1.0.25)

πŸ“„ 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

Hadi Cahyadi

πŸ’– Support

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! ⭐:

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

πŸ™ Acknowledgments

🌟 PT: More than a clipboard tool – it's your file version manager with context!

Save, compare, restore, diff, and manage all your file versions effortlessly with meaningful comments. Never lose work again, and always know why changes were made!

πŸŽ“ Quick Start Tutorial

5-Minute Guide to Master PT

# 1. Install PT
go install github.com/cumulus13/pt-go/pt@latest

# 2. Save your first file with a comment ✨ NEW!
echo "Hello PT" | pbcopy
pt notes.txt -m "Initial version"

# 3. Make changes with context ✨ NEW!
echo "Hello PT v2" | pbcopy
pt notes.txt -m "Added version number"

# 4. See your versions with comments ✨ NEW!
pt -l notes.txt
# Shows table with all versions and their comments

# 5. Use check mode to save space ✨ NEW!
echo "Hello PT v2" | pbcopy  # Same content
pt notes.txt -c -m "Attempted update"
# ℹ️  Content identical, no backup created

# 6. Compare versions
pt -d notes.txt --last

# 7. Restore if needed with context ✨ NEW!
pt -r notes.txt --last -m "Rollback for testing"

# 8. Set up your preferences ✨ NEW!
pt config init
pt config show

# Congratulations! You're now a PT expert with version context! πŸŽ‰

πŸ”₯ Start managing your file versions with meaningful context like a pro today!