Skip to content

Instantly share code, notes, and snippets.

@agriffis
Created February 12, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agriffis/2f1344eb6f740fe1e24935d9d262ad88 to your computer and use it in GitHub Desktop.
Save agriffis/2f1344eb6f740fe1e24935d9d262ad88 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# clipboard provider for neovim
#
# :help provider-clipboard
exec 2>> ~/clipboard-provider.out
set -x
: ${COPY_PROVIDERS:=tmux osc52}
: ${PASTE_PROVIDERS:=tmux}
main() {
declare buffer
case $1 in
copy)
buffer=$(base64)
internal() { base64 -d <<<"$buffer"; }
for p in $COPY_PROVIDERS; do
internal | $p-provider copy
done ;;
paste)
for p in $PASTE_PROVIDERS; do
$p-provider paste && break
done ;;
esac
exit 0
}
tmux-provider() {
[[ -n $TMUX ]] || return
case $1 in
copy) internal | tmux load-buffer - ;;
paste) tmux save-buffer - ;;
esac
}
osc52-provider() {
# HACK: this ignores stdin and looks directly at the base64 buffer
case $1 in
copy) printf $'\e]52;c;%s\a' "$buffer" > /dev/tty ;;
paste) return 1 ;;
esac
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment