Created
January 17, 2026 18:47
-
-
Save s3rvac/414c8b3e988738a8ec7a740316016de9 to your computer and use it in GitHub Desktop.
CopyQ command for removing leading/trailing whitespace upon copying content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // A CopyQ (https://github.com/hluk/CopyQ) command for removing leading/trailing | |
| // whitespace upon copying content. Works for both plain and Rich (HTML) text. | |
| // | |
| // Installation: | |
| // - Open CopyQ, go to File -> Commands (or press F6). | |
| // - Click "+ Add", select "New command". Then, select type "Automatic". | |
| // - Copy the following code there and click on "Apply". | |
| // | |
| copyq: | |
| // Trim plain text. | |
| var text = str(clipboard(mimeText)); | |
| if (text) { | |
| var trimmed = text.trim(); | |
| if (trimmed != text) { | |
| copy(mimeText, trimmed) | |
| } | |
| } | |
| // Trim HTML while preserving formatting. | |
| var html = str(clipboard(mimeHtml)); | |
| if (html) { | |
| var trimmed = html | |
| .replace(/^(\s| |<br\s*\/?>)+/i, "") | |
| .replace(/(\s| |<br\s*\/?>)+$/i, ""); | |
| if (trimmed != html) { | |
| copy(mimeHtml, trimmed) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment