From b137fe275cb9efe557a4e6bae74f3add54c373da Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Tue, 1 Aug 2023 10:40:19 -0400 Subject: [PATCH] tmux: improve clipboard compatibility --- src/.config/tmux/tmux.conf | 2 +- src/.local/bin/cb.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 src/.local/bin/cb.sh diff --git a/src/.config/tmux/tmux.conf b/src/.config/tmux/tmux.conf index e1cbdaa..8831e25 100644 --- a/src/.config/tmux/tmux.conf +++ b/src/.config/tmux/tmux.conf @@ -87,4 +87,4 @@ bind -n C-M-n newpanecurdir bind -T copy-mode-vi v send -X begin-selection bind -T copy-mode-vi V send -X select-line -bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'cb.sh set' diff --git a/src/.local/bin/cb.sh b/src/.local/bin/cb.sh new file mode 100755 index 0000000..3680e6a --- /dev/null +++ b/src/.local/bin/cb.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# clipboard wrapper + +no_provider () { + echo "no providers for clipboard found!" + echo "supported: termux-api, xsel, xclip" +} + +if [ "$1" = "set" ]; then + if command -v xsel > /dev/null; then + xsel -ib + elif command -v termux-clipboard-set > /dev/null; then + cat /dev/stdin | termux-clipboard-set + else + no_provider + fi +elif [ "$1" = "get" ]; then + if command -v xsel > /dev/null; then + xsel -b + elif command -v termux-clipboard-set > /dev/null; then + termux-clipboard-get + else + no_provider + fi +else + echo "usage: cb.sh get/set" + echo "pipe in data" +fi