Copy clipboard history selection with Shift Return

This commit is contained in:
David Heinemeier Hansson
2026-05-29 13:15:00 +02:00
parent cf3a481224
commit bb0d9dd2e3
4 changed files with 66 additions and 5 deletions
+14 -2
View File
@@ -2,19 +2,31 @@
# omarchy:summary=Copy a file to the clipboard and paste it # omarchy:summary=Copy a file to the clipboard and paste it
# omarchy:group=clipboard # omarchy:group=clipboard
# omarchy:args=<mime-type> <path> # omarchy:args=[--copy-only] <mime-type> <path>
# omarchy:examples=omarchy clipboard paste file image/png /tmp/screenshot.png # 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:-} mime=${1:-}
path=${2:-} path=${2:-}
if [[ -z $mime || -z $path ]]; then if [[ -z $mime || -z $path ]]; then
echo "Usage: omarchy-clipboard-paste-file <mime-type> <path>" >&2 echo "Usage: omarchy-clipboard-paste-file [--copy-only] <mime-type> <path>" >&2
exit 1 exit 1
fi fi
[[ -r $path ]] || exit 1 [[ -r $path ]] || exit 1
wl-copy --type "$mime" < "$path" wl-copy --type "$mime" < "$path"
if [[ $copy_only == "true" ]]; then
exit
fi
sleep 0.15 sleep 0.15
wtype -M shift -k Insert -m shift 2>/dev/null || true wtype -M shift -k Insert -m shift 2>/dev/null || true
+13 -2
View File
@@ -2,10 +2,11 @@
# omarchy:summary=Copy text to the clipboard and type or paste it # omarchy:summary=Copy text to the clipboard and type or paste it
# omarchy:group=clipboard # omarchy:group=clipboard
# omarchy:args=[--shift-insert] [--history-index <index>|<text>] # omarchy:args=[--shift-insert] [--copy-only] [--history-index <index>|<text>]
# omarchy:examples=omarchy clipboard paste text "hello" | omarchy clipboard paste text --shift-insert "hello" # omarchy:examples=omarchy clipboard paste text "hello" | omarchy clipboard paste text --shift-insert "hello"
use_shift_insert=false use_shift_insert=false
copy_only=false
history_index="" history_index=""
text="" text=""
@@ -15,6 +16,10 @@ while [[ $# -gt 0 ]]; do
use_shift_insert=true use_shift_insert=true
shift shift
;; ;;
--copy-only)
copy_only=true
shift
;;
--history-index) --history-index)
history_index="${2:-}" history_index="${2:-}"
shift 2 shift 2
@@ -35,13 +40,19 @@ copy_history_entry() {
if [[ -n $history_index ]]; then if [[ -n $history_index ]]; then
copy_history_entry copy_history_entry
use_shift_insert=true if [[ $copy_only != "true" ]]; then
use_shift_insert=true
fi
else else
text=${1:-} text=${1:-}
[[ -n $text ]] || exit [[ -n $text ]] || exit
printf '%s' "$text" | wl-copy printf '%s' "$text" | wl-copy
fi fi
if [[ $copy_only == "true" ]]; then
exit
fi
sleep 0.15 sleep 0.15
if [[ $use_shift_insert == "true" ]]; then if [[ $use_shift_insert == "true" ]]; then
+18 -1
View File
@@ -175,6 +175,12 @@ Item {
root.applySelected(row) root.applySelected(row)
} }
function copyIndex(index) {
if (index < 0 || index >= displayModel.count) return
var row = displayModel.get(index)
root.copySelected(row)
}
function applySelected(row) { function applySelected(row) {
if (!row) return if (!row) return
root.opened = false 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 Component.onCompleted: initProc.running = true
ListModel { id: displayModel } ListModel { id: displayModel }
@@ -295,7 +311,8 @@ Item {
root.select(6) root.select(6)
event.accepted = true event.accepted = true
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { } 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 else if (displayModel.count > 0) root.cursorActive = true
event.accepted = true event.accepted = true
} else if (event.text && event.text.length === 1 && event.text.charCodeAt(0) >= 32 && event.text.charCodeAt(0) !== 127) { } else if (event.text && event.text.length === 1 && event.text.charCodeAt(0) >= 32 && event.text.charCodeAt(0) !== 127) {
+21
View File
@@ -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" [[ $(<"$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" 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"