From 619da2caf28e8fb75d0ef44747540283388d5dde Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:53:08 +0100 Subject: [PATCH] Add cb (https://github.com/niedzielski/cb) --- private_dot_local/bin/executable_cb | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 private_dot_local/bin/executable_cb diff --git a/private_dot_local/bin/executable_cb b/private_dot_local/bin/executable_cb new file mode 100644 index 0000000..1eb491e --- /dev/null +++ b/private_dot_local/bin/executable_cb @@ -0,0 +1,46 @@ +#!/usr/bin/env sh + +# Source: https://github.com/niedzielski/cb + +# If not sourced, set safety options. +case "$0" in */cb) set -eu ;; esac + +case "${OSTYPE:-}$(uname)" in + [lL]inux*) ;; + [dD]arwin*) mac_os=1 ;; + [cC]ygwin) win_os=1 ;; + *) echo "Unknown operating system \"${OSTYPE:-}$(uname)\"." >&2; false ;; +esac + +#is_wayland() { [ "$XDG_SESSION_TYPE" = 'wayland' ]; } +is_wayland() { [ 1 -eq 0 ]; } +is_mac() { [ ${mac_os-0} -ne 0 ]; } +is_win() { [ ${win_os-0} -ne 0 ]; } + +if is_mac; then + alias cbcopy=pbcopy + alias cbpaste=pbpaste +elif is_win; then + alias cbcopy=putclip + alias cbpaste=getclip +else + if is_wayland; then + alias cbcopy=wl-copy + alias cbpaste=wl-paste + else + alias cbcopy='xclip -sel c' + alias cbpaste='xclip -sel c -o' + fi +fi + +cb() { + if [ ! -t 0 ] && [ $# -eq 0 ]; then + # No stdin and no call for --help, blow away the current clipboard and copy. + cbcopy + else + cbpaste "$@" + fi +} + +# If not sourced, execute. +case "$0" in */cb) cb "$@" ;; esac