Created
July 10, 2022 12:15
-
-
Save ivanrad/ea54b3845897ce0b69e20557dbf11df0 to your computer and use it in GitHub Desktop.
copy to clipboard using OSC 52 terminal sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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