How to send command output to GNU Screen’s copy mode buffer

copy/pastegnu-screen

Is there a way to send the output of a command to a GNU Screen's copy mode buffer. I'd like to type something like this:

$ echo 'this is an example' | screen_send_to_copy_mode

or, maybe

Ca Some key

and then, after that, when I pressed C] I would get this is an example as an output. Is it even possible?

Best Answer

You could do something like:

screen_send_to_copy_mode() (
  tmp=$(mktemp) || exit
  cat > "$tmp" &&
    screen -X readbuf "$tmp"
  ret=$?
  (sleep 2; rm -f -- "$tmp")&
  exit "$ret"
)

echo 'this is an example' | screen_send_to_copy_mode