Created
February 12, 2018 19:11
-
-
Save agriffis/2f1344eb6f740fe1e24935d9d262ad88 to your computer and use it in GitHub Desktop.
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 | |
# | |
# 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