cb: cross-platform clipboard script added

wayland support 👍
This commit is contained in:
dogeystamp 2024-08-16 11:39:11 -04:00
parent 28f20bc15f
commit 95138d0ddf
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
6 changed files with 52 additions and 35 deletions

View File

@ -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 'cb.sh set'
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'cb set'

View File

@ -3,7 +3,7 @@
TMPFILE="$(mktemp)"
xsel -b > "$TMPFILE"
cb > "$TMPFILE"
newterm() {
alacritty msg create-window "$@" ||
@ -15,4 +15,4 @@ newterm \
-o 'window.opacity = 1.0' \
-o 'window.dimensions = { columns = 84, lines = 10 }' \
-o 'window.position = { x = 0, y = 1200 }' \
-e sh -c "xsel -b > '$TMPFILE'; nvim -c 'set binary noeol textwidth=80' '$TMPFILE' && cat '$TMPFILE' | xsel -ib && rm '$TMPFILE'"
-e sh -c "cb > '$TMPFILE'; nvim -c 'set binary noeol textwidth=80' '$TMPFILE' && cat '$TMPFILE' | cb set && rm '$TMPFILE'"

View File

@ -1,8 +1,8 @@
#!/bin/sh
# Copy a bookmark to clipboard.
#
# Requires fzf, xsel
# Bookmarks are stored in ~/dox/not/bk.txt, commented with #
# Requires fzf, cb (script in this repo)
# Bookmarks are stored in ~/dox/not/bk.txt, commented with ^
# -o: print to stdout
# -b: open in browser
@ -26,7 +26,7 @@ if [ "$action" = "stdout" ]; then
printf "%s" "$output"
fi
if [ "$action" = "clip" ]; then
printf "%s" "$output" | xsel -ib
printf "%s" "$output" | cb set
fi
if [ "$action" = "browser" ]; then
$BROWSER "$output"

View File

@ -0,0 +1,45 @@
#!/bin/sh
# cross-platform clipboard wrapper
# drop-in replacement for xsel wherever used in my dotfiles
err () {
echo $@ 1>&2
}
no_provider () {
err "no providers for clipboard found!"
err "supported: termux-api, xsel, wl-clipboard"
}
if [ -z "$1" ] || [ "$1" = "-b" ]; then
if [ -n "$WAYLAND_DISPLAY" ]; then
if command -v wl-paste > /dev/null; then
wl-paste
fi
else
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
fi
elif [ "$1" = "-i" ] || [ "$1" = "set" ]; then
if [ -n "$WAYLAND_DISPLAY" ]; then
if command -v wl-copy > /dev/null; then
wl-copy
fi
else
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
fi
else
err "usage: cb [-i] [set] [--help]"
err "communicates via stdout/stdin."
fi

View File

@ -1,28 +0,0 @@
#!/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

View File

@ -2,7 +2,7 @@
# Append link from clipboard/argument to mpv playlist
if [ -z "$2" ]; then
path="$(xsel -b)"
path="$(cb)"
else
path="$2"
fi