Skip to content

Instantly share code, notes, and snippets.

@ivanrad
Created July 10, 2022 12:15
Show Gist options
  • Save ivanrad/ea54b3845897ce0b69e20557dbf11df0 to your computer and use it in GitHub Desktop.
Save ivanrad/ea54b3845897ce0b69e20557dbf11df0 to your computer and use it in GitHub Desktop.
copy to clipboard using OSC 52 terminal sequence
#!/usr/bin/env bash
set -e
buf=$(cat "${@:--}" | base64 | tr -d '\n')
# OSC 52 term seq
seq="\033]52;c;${buf}\a"
if [ -n "${SSH_TTY}" ]; then
printf "$seq" > "${SSH_TTY}"
elif [ -n "${TMUX}" ]; then
client_tty=$(tmux display-message -p '#{client_tty}')
if [ -n "${client_tty}" ]; then
printf "$seq" > "${client_tty}"
fi
else
printf "$seq"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment