Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions services/ClipboardWriter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down
4 changes: 3 additions & 1 deletion tests/privacy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down