Skip to content

Instantly share code, notes, and snippets.

@aanari
Last active July 23, 2022 16:05
Show Gist options
  • Save aanari/ec30594dbde5d13fdc58f9e10b72191b to your computer and use it in GitHub Desktop.
Save aanari/ec30594dbde5d13fdc58f9e10b72191b to your computer and use it in GitHub Desktop.
Custom xclip for clipboard sync (Local WSL 2.0, Remote SSH)
#!/bin/bash
# Copy this to /usr/local/bin/xclip
stdin="$([[ -p /dev/stdin ]] && cat -)"
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
SESSION_TYPE=remote/ssh
else
case $(ps -o comm= -p "$PPID") in
sshd|*/sshd) SESSION_TYPE=remote/ssh;;
esac
fi
if [ "$SESSION_TYPE" == "remote/ssh" ]; then
lemonade copy "$stdin"
else
echo "$stdin" | win32yank.exe -i
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment