Created
February 21, 2019 02:47
-
-
Save KirinDave/cc087efb43c364aadbc57bb497d7e4c3 to your computer and use it in GitHub Desktop.
OSC 52 CopyFile Script
This file contains 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
#!/bin/bash | |
# Convenient when you're using lots of in-browser terminals. | |
set -eu | |
MAXLEN=74994 | |
TARGET=$1 | |
if [ -f $TARGET ]; then | |
echo "Copying $TARGET to clipboard" >&2 | |
DATA=$( cat "$TARGET" ) | |
LEN=$( cat "$TARGET" | wc -c ) | |
if [ "$LEN" -gt "$MAXLEN" ]; then | |
printf "Input is %d bytes too long" "$(( LEN - MAXLEN ))" >&2 | |
fi | |
printf "\033]52;c;$(printf %s "$DATA" | head -c $MAXLEN | base64 | tr -d '\n\r')\a" | |
else | |
echo "No such file: $1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment