From 7a22b06b81d012121cff7a074f533cb377312d44 Mon Sep 17 00:00:00 2001 From: Armando Claudio Date: Sun, 15 Nov 2026 22:20:04 -0400 Subject: [PATCH] Copy untyped text as text/plain instead of a sniffed type ClipboardWriter's scripts pass ${1:+--type "$1"}, so calculator results, emoji and other text copies go to wl-copy with no type, and wl-copy sniffs stdin: "4" is offered only as application/octet-stream and "%PDF-1.4" only as application/pdf, so neither pastes as text nor reaches Omarchy's clipboard history. Default the type to text/plain; explicit types from Clipboard History are unchanged. --- services/ClipboardWriter.qml | 8 +++++--- tests/privacy.test.js | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/services/ClipboardWriter.qml b/services/ClipboardWriter.qml index 690d158..3ae6f22 100644 --- a/services/ClipboardWriter.qml +++ b/services/ClipboardWriter.qml @@ -26,12 +26,14 @@ Item { } // Constant scripts: no caller text ever reaches the command line. $1 is a - // MIME type, $2 a file to copy instead of stdin. - readonly property string copyScript: 'if [[ $2 ]]; then exec wl-copy ${1:+--type "$1"} <"$2"; else exec wl-copy ${1:+--type "$1"}; fi' + // MIME type, $2 a file to copy instead of stdin. Text with no type is + // text/plain: bare wl-copy sniffs stdin, and a value like "4" or "%PDF-1" + // would then be offered only as a non-text type. + readonly property string copyScript: 'if [[ $2 ]]; then exec wl-copy --type "${1:-text/plain}" <"$2"; else exec wl-copy --type "${1:-text/plain}"; fi' // Wait for the launcher to unmap, as omarchy-clipboard-paste-text does. // Terminals take Ctrl+Shift+V (SPEC §5.3): most map Shift+Insert to the // primary selection, and Herdr passes it to the pane's program. - readonly property string pasteScript: 'if [[ $2 ]]; then wl-copy ${1:+--type "$1"} <"$2"; else wl-copy ${1:+--type "$1"}; fi || exit; sleep 0.15 + readonly property string pasteScript: 'if [[ $2 ]]; then wl-copy --type "${1:-text/plain}" <"$2"; else wl-copy --type "${1:-text/plain}"; fi || exit; sleep 0.15 class=$(hyprctl activewindow -j 2>/dev/null | jq -r ".class // empty" 2>/dev/null) case ${class,,} in *alacritty*|*kitty*|foot|footclient|*wezterm*|*ghostty*|*konsole*|*gnome-terminal*|*gnome.terminal*|*ptyxis*|*herdr*) diff --git a/tests/privacy.test.js b/tests/privacy.test.js index 144fae9..b0903be 100644 --- a/tests/privacy.test.js +++ b/tests/privacy.test.js @@ -131,7 +131,9 @@ function runClipboardScript(t, kind, windowClass) { for (const kind of ["copy", "paste"]) { test(`calculator ${kind} keeps the text out of every command line`, (t) => { - runClipboardScript(t, kind, "") + const cmdlines = runClipboardScript(t, kind, "") + // No MIME type means text: bare wl-copy would sniff "4" as a non-text type. + assert.match(cmdlines, /wl-copy --type text\/plain/, "offer the text as text, not a sniffed type") // $1 is a MIME type and $2 a file in our clipboard dir (ClipboardWriter.send); // $@, $*, $3… would mean more of the caller's data on the command line. assert.doesNotMatch(clipboardScripts()[kind], /\$\{?([03-9@*#])/, "the script reads only $1 and $2")