BangSo/infra/sandboxes/computer/paste-text.sh

23 lines
527 B
Bash

#!/usr/bin/env bash
set -euo pipefail
if [[ "$#" -ne 1 ]]; then
echo "usage: rakazo-paste TEXT" >&2
exit 2
fi
printf '%s' "$1" | xclip -selection clipboard -in
window_id="$(xdotool getactivewindow 2>/dev/null || true)"
window_class="$(xprop -id "$window_id" WM_CLASS 2>/dev/null || true)"
case "$window_class" in
*XTerm* | *xterm*)
printf '%s' "$1" | xclip -selection primary -in -loops 5
sleep 0.1
paste_key="shift+Insert"
;;
*) paste_key="ctrl+v" ;;
esac
xdotool key --clearmodifiers "$paste_key"