A versatile tool that helps you copy file contents or Go code snippets to your clipboard. It's particularly useful when working with large language models (LLMs) for code analysis or sharing multiple files.
- Reads contents of multiple files given as command-line arguments
- Walks directories recursively to gather all files
- Prefixes each file's content with a comment showing the file name
- Ignores non-text files
- Can exclude files matching specified patterns
- Finds and extracts specified Go functions from your codebase
- Analyzes and includes function dependencies
- Captures related type definitions and helper functions
- Preserves file and line number information
- Formats output for easy copying into LLMs
- Go 1.15 or higher
- Ensure you have Go installed from golang.org
- Install the tool:
go install github.com/LeanerCloud/f2c/cmd/f2c@latest
Copy contents of specific files or directories:
# Copy all text files in current directory
f2c .
# Copy specific files
f2c file1.txt file2.go
# Exclude certain paths
f2c --exclude .git,vendor,node_modules .
# Short form for exclude
f2c -e .git,vendor .
Example output:
// file1.txt
Hello, this is file1.
// file2.txt
Hello, this is file2.
Extract a function and its dependencies from the current directory:
# Extract a specific function
f2c --function ProcessDirectory
# Short form
f2c -f ProcessDirectory
Example output:
// main.go:40 ProcessDirectory
func ProcessDirectory(path string) error {
// ... function code ...
}
// utils.go:15 helperFunction
func helperFunction() {
// ... dependency code ...
}
// types.go:25 Config
type Config struct {
// ... related type definition ...
}
f2c [flags] [file/directory...]
Flags:
-e, --exclude string Comma-separated list of strings to exclude when appearing in file names
-f, --function string Name of the Go function to analyze
-h, --help Help for f2c
- Recursively scans provided paths
- Identifies text files using content type detection
- Skips excluded paths
- Reads and formats file contents
- Copies combined output to clipboard
- Locates target function in Go source files
- Analyzes function dependencies (types, helper functions)
- Collects all related code snippets
- Preserves source location information
- Copies formatted output to clipboard
This project is licensed under the MIT License.