diff --git a/src/ziggy/commands/clipboard.go b/src/ziggy/commands/clipboard.go index 0c661ce3..d5fa22b1 100644 --- a/src/ziggy/commands/clipboard.go +++ b/src/ziggy/commands/clipboard.go @@ -1,8 +1,10 @@ package commands import ( + "errors" "flag" "fmt" + "strings" "uosc/bins/src/ziggy/lib" "github.com/atotto/clipboard" @@ -13,8 +15,18 @@ type ClipboardResult struct { } func GetClipboard(_ []string) { + // We need to do this instead of just `Payload: lib.Must(clipboard.ReadAll())` because + // the atotto/clipboard returns unhelpful messages like "the operation completed successfully". + payload, err := clipboard.ReadAll() + if err != nil { + if strings.Contains(strings.ToLower(err.Error()), "successfully") { + lib.Check(errors.New("clipboard format not supported")) + } + lib.Check(err) + } + fmt.Print(string(lib.Must(lib.JSONMarshal(ClipboardResult{ - Payload: lib.Must(clipboard.ReadAll()), + Payload: payload, })))) }