├── go.mod ├── go.sum └── main.go /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/phillip-england/rpp 2 | 3 | go 1.25.3 4 | 5 | require github.com/atotto/clipboard v0.1.4 // indirect 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= 2 | github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= 3 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/atotto/clipboard" 8 | ) 9 | 10 | func main() { 11 | if len(os.Args) < 2 { 12 | fmt.Println("Usage: rpp ") 13 | os.Exit(1) 14 | } 15 | 16 | targetFile := os.Args[1] 17 | 18 | // Check file status 19 | info, err := os.Stat(targetFile) 20 | if err == nil { 21 | // Path exists — ensure it's not a directory 22 | if info.IsDir() { 23 | fmt.Printf("Error: '%s' is a directory, not a file.\n", targetFile) 24 | os.Exit(1) 25 | } 26 | } else if !os.IsNotExist(err) { 27 | // Some other filesystem error 28 | fmt.Printf("Error checking file: %v\n", err) 29 | os.Exit(1) 30 | } 31 | // If os.IsNotExist(err) → this is OK, we'll create the file 32 | 33 | // Read clipboard 34 | content, err := clipboard.ReadAll() 35 | if err != nil { 36 | fmt.Printf("Error reading clipboard: %v\n", err) 37 | os.Exit(1) 38 | } 39 | 40 | // Write file (creates if missing, truncates if exists) 41 | err = os.WriteFile(targetFile, []byte(content), 0644) 42 | if err != nil { 43 | fmt.Printf("Error writing to file: %v\n", err) 44 | os.Exit(1) 45 | } 46 | 47 | fmt.Printf("Successfully wrote clipboard contents to '%s'.\n", targetFile) 48 | } 49 | --------------------------------------------------------------------------------