Skip to content

Commit cf611c7

Browse files
committed
feat: add automatic clipboard copy functionality
- Add clipboard library (github.com/atotto/clipboard v0.1.4) - Auto-copy generated commit message to clipboard - Show success feedback: '📋 Commit message copied to clipboard!' - Graceful error handling if clipboard access fails - Users can immediately paste with Ctrl+V/Cmd+V
1 parent a854b71 commit cf611c7

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
2222
cloud.google.com/go/compute/metadata v0.6.0 // indirect
2323
cloud.google.com/go/longrunning v0.5.7 // indirect
24+
github.com/atotto/clipboard v0.1.4 // indirect
2425
github.com/containerd/console v1.0.5 // indirect
2526
github.com/felixge/httpsnoop v1.0.4 // indirect
2627
github.com/go-logr/logr v1.4.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYew
2828
github.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4=
2929
github.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY=
3030
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
31+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
32+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
3133
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
3234
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
3335
github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=

src/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"strings"
1010

11+
"github.com/atotto/clipboard"
1112
"github.com/dfanso/commit-msg/src/chatgpt"
1213
"github.com/dfanso/commit-msg/src/gemini"
1314
"github.com/dfanso/commit-msg/src/grok"
@@ -132,6 +133,14 @@ func main() {
132133
// Display the commit message in a styled panel
133134
displayCommitMessage(commitMsg)
134135

136+
// Copy to clipboard
137+
err = clipboard.WriteAll(commitMsg)
138+
if err != nil {
139+
pterm.Warning.Printf("⚠️ Could not copy to clipboard: %v\n", err)
140+
} else {
141+
pterm.Success.Println("📋 Commit message copied to clipboard!")
142+
}
143+
135144
pterm.Println()
136145

137146
// Display changes preview

0 commit comments

Comments
 (0)