Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 68 lines (56 sloc) 1.51 KB
#!/bin/bash
# Taken and modified from https://github.com/agriffis/skel/blob/master/neovim/bin/clipboard-provider
#
# clipboard provider for neovim
#
# :help provider-clipboard
#exec 2>> ~/clipboard-provider.out
#set -x
: ${COPY_PROVIDERS:=tmux pb osc52 local}
: ${PASTE_PROVIDERS:=pb tmux local}
: ${TTY:=`(tty || tty </proc/$PPID/fd/0) 2>/dev/null | grep /dev/`}
LOCAL_STORAGE=$HOME/.clipboard-provider.out
main() {
declare buffer status=1
case $1 in
copy)
buffer=$(base64 | tr -d '\n')
internal() { base64 --decode <<<"$buffer"; }
for p in $COPY_PROVIDERS; do
internal | $p-provider copy && status=0
done ;;
paste)
for p in $PASTE_PROVIDERS; do
$p-provider paste && status=0 && break
done ;;
esac
exit $status
}
tmux-provider() {
[[ -n $TMUX ]] || return
case $1 in
copy) internal | tmux load-buffer - ;;
paste) tmux save-buffer - ;;
esac
}
pb-provider() {
if ! command -v pbcopy &>/dev/null;then return; fi
case $1 in
copy) internal | pbcopy ;;
paste) pbpaste ;;
esac
}
osc52-provider() {
# HACK: this ignores stdin and looks directly at the base64 buffer
case $1 in
copy) [[ -n "$TTY" ]] && printf $'\e]52;c;%s\a' "$buffer" > "$TTY" ;;
paste) return 1 ;;
esac
}
local-provider() {
case $1 in
copy) internal > $LOCAL_STORAGE ;;
paste) cat $LOCAL_STORAGE && return 0;;
esac
}
main "$@"
You can’t perform that action at this time.