#!/usr/bin/env sh
#
# pbpaste - clipboard wrapper: wl-copy xsel xclip

if [ "${XDG_SESSION_TYPE-}" = "wayland" ]; then
  if command -v wl-paste >/dev/null 2>&1; then
    WAYLAND_DISPLAY=wayland-0 wl-paste --no-newline "$@"
  else
    echo "wl-clipboard is required" >&2
    exit 1
  fi
elif [ "${XDG_SESSION_TYPE-}" = "x11" ]; then
  if command -v xsel >/dev/null 2>&1; then
    DISPLAY=${DISPLAY:-:0} xsel --clipboard --output "$@"
  elif command -v xclip >/dev/null 2>&1; then
    DISPLAY=${DISPLAY:-:0} xclip -selection clipboard -o "$@"
  else
    echo "xsel or xclip is required" >&2
    exit 1
  fi
fi
