if ! command -v wl-copy >/dev/null \
|| [[
   -n "${SSH_CLIENT-}" ||
   -n "${SSH_TTY-}" ||
   -z "${WAYLAND_DISPLAY-}" ||
   "${XDG_SESSION_TYPE-}" != "wayland"
]]
then
  alias clip="xclip -sel clip -i -rmlastnl -t text/plain"
  alias clip-prev-cmd="HISTTIMEFORMAT=, history 2 | cut -d, -f2- | head -n1 | xclip -sel clip -i -rmlastnl -t text/plain"
else
  alias clip="wl-copy --trim-newline --type text/plain"
  alias clip-prev-cmd="HISTTIMEFORMAT=, history 2 | cut -d, -f2- | head -n1 | wl-copy --trim-newline --type text/plain"
fi
