c2f

Crates.ioc2f
lib.rsc2f
version0.1.0
created_at2025-09-10 07:08:00.751727+00
updated_at2025-09-10 09:29:43.09525+00
descriptionCLI to write clipboard contents to a file
homepagehttps://github.com/balintb/c2f
repositoryhttps://github.com/balintb/c2f
max_upload_size
id1832169
size106,913
Balint (balintb)

documentation

README

c2f - Clipboard to file

Simple CLI tool to write clipboard contents to a file with content format detection.

Overview

c2f is a lightweight cross-platform command-line utility that saves or appends your clipboard contents to a file. It can automatically detect content types and add an appropriate file extension.

Installation

Homebrew (Recommended)

brew install balintb/tap/c2f

Cargo

cargo install c2f

From Source

Requires Rust 1.60+

git clone https://github.com/balintb/c2f
cd c2f
cargo install --path .

Pre-built Binaries

Download the latest release from the releases page.

Usage

# write clipboard with auto-detected extension
c2f
# creates clipboard.json / clipboard.py / clipboard.md / etc.

# write clipboard to specific file
c2f myfile.txt

# append to file
c2f -a existing.txt

# quiet mode (no output)
c2f -q

# override content detection
c2f --detect=false  # always use .txt extension
c2f --detect=true   # force detection even if disabled in config

Options

  • -a, --append - Append to file instead of overwriting
  • -q, --quiet - Suppress all output
  • -e, --append-ext - Add detected extension to specified filename
  • --detect=<bool> - Override content detection (true/false)
  • -h, --help - Print help
  • -V, --version - Print version

Configuration

c2f supports a configuration file at ~/.config/c2f/config.toml:

ask_confirmation = false  # Ask for confirmation before writing (default: false)
quiet = false             # Suppress all output (default: false)
detect_type = true        # Enable content type detection (default: true)

Command-line flags override config file settings.

Examples

Basic Usage

# copy JSON and save with autodetected extension
echo '{"name": "test"}' | pbcopy  # macOS
c2f  # creates clipboard.json

# copy Python and save
echo 'import sys' | pbcopy
c2f  # creates clipboard.py

# copy MD and save
echo '# Title' | pbcopy
c2f  # creates clipboard.md

Specific Filename

# save to specific file
c2f output.txt

# append to existing file
c2f -a notes.log

# quiet mode (no output)
c2f -q data.json

Detection Control

# disable detection (always use .txt)
c2f --detect=false

# force detection even if disabled in config
c2f --detect=true

# append detected extension to specified filename
echo '{"data": true}' | pbcopy
c2f -e myfile  # creates myfile.json
c2f --append-ext output  # creates output.json

More Examples

# quietly append JSON to log file with explicit detection
echo '{"timestamp": "2025-01-10", "event": "test"}' | pbcopy
c2f -qa --detect=true events.log

# save code snippet with auto-extension in quiet mode
echo 'def hello(): print("world")' | pbcopy
c2f -qe snippet  # creates snippet.py silently

# override config to force detection and append extension
c2f --detect=true --append-ext report  # creates report.{ext} based on content

# copy SQL query and append to daily log
c2f -a ~/logs/queries-$(date +%Y%m%d).sql

# copy code from browser/IDE, then:
c2f -qe ~/snippets/solution  # auto-detects language, adds extension

# append API responses to a file
c2f -qa api-responses.jsonl  # append mode for JSON Lines format

# note-taking: save formatted content with proper extensions
c2f -e ~/notes/$(date +%Y%m%d)-meeting  # creates dated .md file

Supported Formats

c2f can automatically detect and assign appropriate extensions for:

Data Formats: JSON (.json), XML (.xml), YAML (.yaml), TOML (.toml), CSV (.csv), SQL (.sql)

Programming Languages:

  • Rust (.rs), Python (.py), JavaScript (.js), TypeScript (.ts)
  • Go (.go), Java (.java), C# (.cs), C++ (.cpp), C (.c)
  • Shell (.sh), PowerShell (.ps1), Ruby (.rb), PHP (.php)
  • Swift (.swift), Kotlin (.kt)

Markup & Style: HTML (.html), Markdown (.md), LaTeX (.tex), CSS (.css), SCSS (.scss)

Config Files: Dockerfile, .gitignore, Makefile, .env, INI (.ini)

Images: PNG images from clipboard

Fallback: Plain text (.txt) for unrecognized content

Platform Support

c2f is cross-platform:

  • macOS
  • Linux
  • Windows

License

MIT License - see LICENSE for details.

Copyright 2025 balintb

Commit count: 28

cargo fmt