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
18 changes: 18 additions & 0 deletions bin/omarchy-clipboard-paste-file
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ if [[ -z $mime || -z $path ]]; then
exit 1
fi

terminal_focused() {
local class

class=$(hyprctl activewindow -j 2>/dev/null | jq -r ".class // empty" 2>/dev/null) || return 1
[[ -n $class ]] || return 1

class=${class,,}
[[ $class == *term* || $class == *foot* || $class == *kitty* || $class == *ghostty* || $class == *alacritty* || $class == *wezterm* || $class == *konsole* || $class == *tilix* ]]
}

[[ -r $path ]] || exit 1

wl-copy --type "$mime" < "$path"
Expand All @@ -29,5 +39,13 @@ if [[ $copy_only == "true" ]]; then
exit
fi

# Terminals only accept text, so pasting an image into one silently drops it.
# When the focused window is a terminal, type the file path instead.
if [[ $mime == image/* ]] && terminal_focused; then
sleep 0.15
wtype "$path" 2>/dev/null || true
exit
fi

sleep 0.15
wtype -M shift -k Insert -m shift 2>/dev/null || true
2 changes: 1 addition & 1 deletion manual/08-unified-clipboard-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _Note that most agent harnesses will use `Ctrl + V` for pasting images, but `Sup

### Clipboard history

The clipboard history is provided by the Omarchy shell and works for both text and images. You trigger it by `Super + Ctrl + V`, select your entry with return, and then that'll be placed on the clipboard ready to paste on `Super + V`.
The clipboard history is provided by the Omarchy shell and works for both text and images. You trigger it by `Super + Ctrl + V`, select your entry with return, and then that'll be placed on the clipboard ready to paste on `Super + V`. Pasting an image while a terminal is focused types the file path instead, since terminals can only receive text — handy for handing screenshots to CLI tools and agent harnesses.

![clipboard-history](images/clipboard-history.webp)

Expand Down
35 changes: 35 additions & 0 deletions test/shell.d/clipboard-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,41 @@ 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"

cat >"$TMPDIR/bin/hyprctl" <<'SH'
#!/bin/bash
printf '{"class":"%s"}' "${HYPRCTL_CLASS:-}"
SH
chmod +x "$TMPDIR/bin/hyprctl"

rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HYPRCTL_CLASS="foot" PATH="$TMPDIR/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-file" image/png "$TMPDIR/image.png"

[[ $(<"$TMPDIR/wtype") == "$TMPDIR/image.png" ]] || fail "clipboard file paste helper types image path into terminals"
pass "clipboard file paste helper types image path into terminals"

rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HYPRCTL_CLASS="firefox" PATH="$TMPDIR/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-file" image/png "$TMPDIR/image.png"

[[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "clipboard file paste helper pastes images into GUI apps with shift insert"
pass "clipboard file paste helper pastes images into GUI apps with shift insert"

printf 'note text' >"$TMPDIR/note.txt"
rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HYPRCTL_CLASS="foot" PATH="$TMPDIR/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-file" text/plain "$TMPDIR/note.txt"

[[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "clipboard file paste helper pastes non-images into terminals with shift insert"
pass "clipboard file paste helper pastes non-images into terminals with shift insert"

rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HYPRCTL_CLASS="" PATH="$TMPDIR/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-file" image/png "$TMPDIR/image.png"

[[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "clipboard file paste helper falls back to shift insert without focus info"
pass "clipboard file paste helper falls back to shift insert without focus info"

jq -n --arg url 'https://example.com/docs' --arg text "$(printf 'plain text\nsecond line')" --arg image "$TMPDIR/image.png" \
'[{type:"text", text:$url}, {type:"text", text:$text}, {type:"image", mime:"image/png", path:$image}]' >"$TMPDIR/home/.local/state/omarchy/clipboard-history.json"

Expand Down