Tech News
← Home  ·  All topics

Xclip

1 GoKawiil brief on this topic

Developer refines jq clipboard-formatting alias for Linux with error handling

A blog post highlights a handy jq trick from Sequoia McDowell that pretty-prints JSON copied to the clipboard and pastes it back automatically, using pbpaste and pbcopy on macOS. The author adapts this for Linux using xclip, then identifies a flaw: if the clipboard doesn't contain valid JSON, jq fails silently and wipes the clipboard content. The fix adds a fallback so the original clipboard text is preserved when jq errors out.