Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created February 21, 2019 02:47
Show Gist options
  • Save KirinDave/cc087efb43c364aadbc57bb497d7e4c3 to your computer and use it in GitHub Desktop.
Save KirinDave/cc087efb43c364aadbc57bb497d7e4c3 to your computer and use it in GitHub Desktop.
OSC 52 CopyFile Script
#!/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