From bb0d9dd2e3cf257190cd6193c793a5764c425c85 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 May 2026 13:15:00 +0200 Subject: [PATCH] Copy clipboard history selection with Shift Return --- bin/omarchy-clipboard-paste-file | 16 ++++++++++++++-- bin/omarchy-clipboard-paste-text | 15 +++++++++++++-- shell/plugins/clipboard/Clipboard.qml | 19 ++++++++++++++++++- test/shell.d/clipboard-test.sh | 21 +++++++++++++++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-clipboard-paste-file b/bin/omarchy-clipboard-paste-file index 7064e601..a656931b 100755 --- a/bin/omarchy-clipboard-paste-file +++ b/bin/omarchy-clipboard-paste-file @@ -2,19 +2,31 @@ # omarchy:summary=Copy a file to the clipboard and paste it # omarchy:group=clipboard -# omarchy:args= +# omarchy:args=[--copy-only] # omarchy:examples=omarchy clipboard paste file image/png /tmp/screenshot.png +copy_only=false + +if [[ ${1:-} == "--copy-only" ]]; then + copy_only=true + shift +fi + mime=${1:-} path=${2:-} if [[ -z $mime || -z $path ]]; then - echo "Usage: omarchy-clipboard-paste-file " >&2 + echo "Usage: omarchy-clipboard-paste-file [--copy-only] " >&2 exit 1 fi [[ -r $path ]] || exit 1 wl-copy --type "$mime" < "$path" + +if [[ $copy_only == "true" ]]; then + exit +fi + sleep 0.15 wtype -M shift -k Insert -m shift 2>/dev/null || true diff --git a/bin/omarchy-clipboard-paste-text b/bin/omarchy-clipboard-paste-text index 2927260c..a1cf064e 100755 --- a/bin/omarchy-clipboard-paste-text +++ b/bin/omarchy-clipboard-paste-text @@ -2,10 +2,11 @@ # omarchy:summary=Copy text to the clipboard and type or paste it # omarchy:group=clipboard -# omarchy:args=[--shift-insert] [--history-index |] +# omarchy:args=[--shift-insert] [--copy-only] [--history-index |] # omarchy:examples=omarchy clipboard paste text "hello" | omarchy clipboard paste text --shift-insert "hello" use_shift_insert=false +copy_only=false history_index="" text="" @@ -15,6 +16,10 @@ while [[ $# -gt 0 ]]; do use_shift_insert=true shift ;; + --copy-only) + copy_only=true + shift + ;; --history-index) history_index="${2:-}" shift 2 @@ -35,13 +40,19 @@ copy_history_entry() { if [[ -n $history_index ]]; then copy_history_entry - use_shift_insert=true + if [[ $copy_only != "true" ]]; then + use_shift_insert=true + fi else text=${1:-} [[ -n $text ]] || exit printf '%s' "$text" | wl-copy fi +if [[ $copy_only == "true" ]]; then + exit +fi + sleep 0.15 if [[ $use_shift_insert == "true" ]]; then diff --git a/shell/plugins/clipboard/Clipboard.qml b/shell/plugins/clipboard/Clipboard.qml index 6508cf69..e06d82e9 100644 --- a/shell/plugins/clipboard/Clipboard.qml +++ b/shell/plugins/clipboard/Clipboard.qml @@ -175,6 +175,12 @@ Item { root.applySelected(row) } + function copyIndex(index) { + if (index < 0 || index >= displayModel.count) return + var row = displayModel.get(index) + root.copySelected(row) + } + function applySelected(row) { if (!row) return root.opened = false @@ -185,6 +191,16 @@ Item { } } + function copySelected(row) { + if (!row) return + root.opened = false + if (row.entryType === "image") { + Quickshell.execDetached([root.omarchyPath + "/bin/omarchy-clipboard-paste-file", "--copy-only", row.mime, row.path]) + } else if (row.fullText) { + Quickshell.execDetached([root.omarchyPath + "/bin/omarchy-clipboard-paste-text", "--copy-only", "--history-index", String(row.index)]) + } + } + Component.onCompleted: initProc.running = true ListModel { id: displayModel } @@ -295,7 +311,8 @@ Item { root.select(6) event.accepted = true } else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { - if (root.cursorActive) root.activateIndex(root.selectedIndex) + if (root.cursorActive && (event.modifiers & Qt.ShiftModifier)) root.copyIndex(root.selectedIndex) + else if (root.cursorActive) root.activateIndex(root.selectedIndex) else if (displayModel.count > 0) root.cursorActive = true event.accepted = true } else if (event.text && event.text.length === 1 && event.text.charCodeAt(0) >= 32 && event.text.charCodeAt(0) !== 127) { diff --git a/test/shell.d/clipboard-test.sh b/test/shell.d/clipboard-test.sh index 650d3e30..0a991eda 100644 --- a/test/shell.d/clipboard-test.sh +++ b/test/shell.d/clipboard-test.sh @@ -108,3 +108,24 @@ pass "clipboard paste helper copies history entry text" [[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "clipboard paste helper pastes history entries with shift insert" pass "clipboard paste helper pastes history entries with shift insert" + +rm -f "$TMPDIR/wtype" +WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$PATH" \ + "$ROOT/bin/omarchy-clipboard-paste-text" --copy-only --history-index 1 + +[[ $(<"$TMPDIR/copied") == "$(printf 'large block line 1\nlarge block line 2')" ]] || fail "clipboard paste helper copy-only copies history entry text" +pass "clipboard paste helper copy-only copies history entry text" + +[[ ! -e "$TMPDIR/wtype" ]] || fail "clipboard paste helper copy-only skips typing" +pass "clipboard paste helper copy-only skips typing" + +printf 'image-data' >"$TMPDIR/image.png" +rm -f "$TMPDIR/wtype" +WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" PATH="$TMPDIR/bin:$PATH" \ + "$ROOT/bin/omarchy-clipboard-paste-file" --copy-only image/png "$TMPDIR/image.png" + +[[ $(<"$TMPDIR/copied") == "image-data" ]] || fail "clipboard file paste helper copy-only copies file content" +pass "clipboard file paste helper copy-only copies file content" + +[[ ! -e "$TMPDIR/wtype" ]] || fail "clipboard file paste helper copy-only skips paste keystroke" +pass "clipboard file paste helper copy-only skips paste keystroke"