#!/usr/bin/env bash
# Handy's paste step, as its "External Script" paste method (2026-10-19).
#
# Does what Handy's own "Clipboard (Shift+Insert)" method does (put the text on
# the clipboard, press Shift+Insert), minus the first step: Handy 0.9.8 reads the
# old clipboard before pasting, on its UI thread and with no timeout. When the
# clipboard's owner doesn't answer, that read never returns and Handy freezes
# for good (2026-10-19, twice). This script never reads the clipboard.
#
# Handy runs it with the text as the only argument and waits for it to exit.
# Clipboard Handling "Copy to Clipboard" still leaves the text on the clipboard.
set -u

text=${1-}
[ -n "$text" ] || exit 0

# wl-copy forks a helper that holds the clipboard and returns at once.
timeout 2 wl-copy -- "$text" || exit 1
sleep 0.06

# Shift+Insert as raw keycodes (ydotool 1.x): 42 = Left Shift, 110 = Insert.
timeout 2 ydotool key 42:1 110:1 110:0 42:0
