#!/bin/bash

case "$(uname -s)" in
Darwin)
  command -v pbpaste &>/dev/null ||
    {
      echo "Error: pbpaste not found" >&2
      exit 1
    }
  pbpaste
  ;;
Linux)
  if command -v wl-paste &>/dev/null; then
    # --no-newline removes the extra \n wl-paste always appends,
    # without touching newlines that are part of the actual content
    wl-paste --no-newline
  elif command -v xclip &>/dev/null; then
    xclip -selection clipboard -o
  elif command -v xsel &>/dev/null; then
    xsel --clipboard --output
  else
    echo "Error: No clipboard tool found (wl-paste, xclip, xsel)" >&2; exit 1
  fi
  ;;
*)
  echo "Error: Unsupported OS '$(uname -s)'" >&2
  exit 1
  ;;
esac
