clippy

package module
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 9 Imported by: 0

README

Clippy 📎

Copy files from your terminal that actually paste into GUI apps. No more switching to Finder.

macOS only - built specifically for the Mac clipboard system.

Why Clippy?

pbcopy copies file contents, but GUI apps need file references. When you pbcopy < image.png, you can't paste it into Slack or email - those apps expect files, not raw bytes.

Clippy bridges this gap by detecting what you want and using the right clipboard format:

# Copy files as references (paste into any GUI app)
clippy report.pdf         # ⌘V into Slack/email - uploads the file
clippy *.jpg             # Multiple files at once

# Copy your most recent download
clippy -r                # Grabs the file you just downloaded
clippy -r 5m             # Only last 5 minutes

# Interactive picker for recent files
clippy -r --pick         # Choose from multiple recent downloads

# Pipe data as files
curl -sL https://picsum.photos/300 | clippy  # Download → clipboard as file

Stay in your terminal. Copy anything. Paste anywhere.

Installation

brew install neilberkman/clippy/clippy
Build from Source
# Clone and build
git clone https://github.com/neilberkman/clippy.git
cd clippy
go build -o clippy ./cmd/clippy
sudo mv clippy /usr/local/bin/

# Or use go install
go install github.com/neilberkman/clippy/cmd/clippy@latest

Core Features

1. Smart File Copying
clippy document.pdf    # Copies as file reference (paste into any app)
clippy notes.txt       # Copies text content
clippy *.jpg          # Multiple files at once
2. Recent Downloads
clippy -r              # Copy your most recent download
clippy -r --pick       # Interactive picker for recent files
clippy -r 5m           # Only last 5 minutes
3. Pipe Data as Files
curl -sL https://example.com/image.jpg | clippy
cat archive.tar.gz | clippy
4. Helpful Flags
clippy -v file.txt     # Show what happened
clippy --debug file.txt # Technical details for debugging

Pasty - Intelligent Clipboard Pasting

Pasty is clippy's companion tool for intelligent pasting from the clipboard.

Core Use Cases

1. Copy file in Finder → Paste in terminal

# 1. Copy any file in Finder (⌘C)
# 2. Switch to terminal and run:
pasty
# File appears in your current directory

2. Download in browser → Paste in terminal

# 1. Download file in browser
# 2. Switch to terminal and run:
pasty -r
# Most recent download appears in your current directory

3. Interactive picker for recent files

pasty -r --pick          # Choose from multiple recent downloads
pasty -r 5m              # Only last 5 minutes

4. Text content handling

# Copy text in any app, then:
pasty                    # Outputs text to stdout
pasty notes.txt          # Saves text to file

Install & Use

# Install via Homebrew
brew install neilberkman/clippy/clippy

# Or build from source
go install github.com/neilberkman/clippy/cmd/clippy@latest
go install github.com/neilberkman/clippy/cmd/pasty@latest

Why "Clippy"?

Because it's a helpful clipboard assistant that knows what you want to do! 📎

License

MIT

Documentation

Overview

Package clippy provides smart clipboard operations for macOS. It automatically detects whether to copy file content or file references using hybrid detection: UTI -> MIME -> mimetype fallback for maximum reliability.

Example
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/neilberkman/clippy"
)

func main() {
	// Copy text to clipboard
	clippy.CopyText("Hello, World!")

	// Copy a file (text files copy content, others copy reference)
	err := clippy.Copy("document.pdf")
	if err != nil {
		log.Fatal(err)
	}

	// Copy multiple files
	err = clippy.CopyMultiple([]string{"image1.jpg", "image2.png"})
	if err != nil {
		log.Fatal(err)
	}

	// Copy from a reader (e.g., from a download)
	reader := strings.NewReader("Some text content")
	err = clippy.CopyData(reader)
	if err != nil {
		log.Fatal(err)
	}

	// Get clipboard content
	if text, ok := clippy.GetText(); ok {
		fmt.Printf("Clipboard text: %s\n", text)
	}

	// Get files from clipboard
	files := clippy.GetFiles()
	for _, file := range files {
		fmt.Printf("File in clipboard: %s\n", file)
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTempFiles added in v0.6.0

func CleanupTempFiles(tempDir string, verbose bool)

CleanupTempFiles removes old temporary files that are no longer in clipboard

func Copy

func Copy(path string) error

Copy intelligently copies a file to clipboard. Text files copy their content, binary files copy file references. Uses hybrid detection: UTI -> MIME -> mimetype fallback.

Example
package main

import (
	"log"

	"github.com/neilberkman/clippy"
)

func main() {
	// Copy a single file intelligently
	err := clippy.Copy("report.pdf")
	if err != nil {
		log.Printf("Failed to copy file: %v", err)
	}
}

func CopyData

func CopyData(reader io.Reader) error

CopyData copies data from a reader to clipboard. Text data is copied as text, binary data is saved to a temp file. Uses MIME type detection for content analysis.

func CopyDataWithTempDir

func CopyDataWithTempDir(reader io.Reader, tempDir string) error

CopyDataWithTempDir is like CopyData but allows specifying a custom temp directory.

func CopyMultiple

func CopyMultiple(paths []string) error

CopyMultiple copies multiple files to clipboard as file references.

func CopyText

func CopyText(text string)

CopyText copies text content to clipboard.

Example
package main

import (
	"github.com/neilberkman/clippy"
)

func main() {
	// Copy text to clipboard
	clippy.CopyText("Hello from clippy library!")
}

func GetFiles

func GetFiles() []string

GetFiles returns file paths from clipboard. Uses hybrid detection for better reliability.

func GetText

func GetText() (string, bool)

GetText returns text content from clipboard. Uses hybrid detection for better reliability.

Example
package main

import (
	"fmt"

	"github.com/neilberkman/clippy"
)

func main() {
	// Get text from clipboard
	if text, ok := clippy.GetText(); ok {
		fmt.Printf("Clipboard contains: %s\n", text)
	} else {
		fmt.Println("No text in clipboard")
	}
}

Types

type CopyResult added in v0.6.0

type CopyResult struct {
	Method   string // "UTI", "MIME", or "content"
	Type     string // The detected type (UTI or MIME)
	AsText   bool   // Whether content was copied as text
	FilePath string // The file path that was copied
}

CopyResult contains information about what was copied and how

func CopyWithResult added in v0.6.0

func CopyWithResult(path string) (*CopyResult, error)

CopyWithResult is like Copy but returns information about the detection method used

type PasteResult added in v0.6.0

type PasteResult struct {
	Type      string   // "text" or "files"
	Content   string   // Text content if Type is "text"
	Files     []string // File paths if Type is "files"
	FilesRead int      // Number of files successfully read/copied
}

PasteResult contains information about what was pasted

func PasteToFile added in v0.6.0

func PasteToFile(destination string) (*PasteResult, error)

PasteToFile pastes clipboard content to a file or directory

func PasteToStdout added in v0.6.0

func PasteToStdout() (*PasteResult, error)

PasteToStdout pastes clipboard content to stdout

Directories

Path Synopsis
cmd
clippy command
pasty command
Pasty - Smart paste tool for macOS Companion to clippy, provides intelligent pasting from clipboard
Pasty - Smart paste tool for macOS Companion to clippy, provides intelligent pasting from clipboard
Example showing how to use clippy as a library
Example showing how to use clippy as a library
internal
log
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL