mirror of
https://github.com/skidoodle/ctx.git
synced 2026-04-28 03:07:41 +02:00
Add cross-platform clipboard support
Implement CopyFile for darwin, linux, and windows and call it from main to copy generated output to the clipboard. Enable CGO for builds, update goreleaser and release workflow to use macOS, and add a cross-platform test workflow that verifies the clipboard.
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/skidoodle/ctx/clipboard"
|
||||
)
|
||||
|
||||
const defaultOutputFilename = "ctx.txt"
|
||||
@@ -21,6 +23,7 @@ func run() error {
|
||||
flag.Usage = usage
|
||||
configFlag := flag.Bool("config", false, "open global ignore file for editing")
|
||||
outputFlag := flag.String("o", defaultOutputFilename, "output filename")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *configFlag {
|
||||
@@ -62,6 +65,12 @@ func run() error {
|
||||
return fmt.Errorf("writing output: %w", err)
|
||||
}
|
||||
|
||||
if err := clipboard.CopyFile(*outputFlag); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ctx: warning: clipboard copy failed: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("ctx: copied %s to clipboard\n", *outputFlag)
|
||||
}
|
||||
|
||||
duration := time.Since(start).Round(time.Millisecond)
|
||||
fmt.Printf("ctx: generated %s (%d files, ~%d tokens) in %v\n",
|
||||
*outputFlag, len(files), tokenCount, duration)
|
||||
@@ -75,7 +84,5 @@ func usage() {
|
||||
fmt.Fprintf(os.Stderr, " -config Open global ignore file for editing\n")
|
||||
fmt.Fprintf(os.Stderr, " -o <file> Output filename (default %q)\n", defaultOutputFilename)
|
||||
fmt.Fprintf(os.Stderr, "\nExamples:\n")
|
||||
fmt.Fprintf(os.Stderr, " ctx . # Generate context for current dir\n")
|
||||
fmt.Fprintf(os.Stderr, " ctx -o out.txt src/ # Scan src/ and save to out.txt\n")
|
||||
fmt.Fprintf(os.Stderr, " ctx -config # Open global ignore file\n")
|
||||
fmt.Fprintf(os.Stderr, " ctx . # Generate and copy file\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user