#!/bin/bash
# WSL2 xclip shim — routes xclip calls to the Windows clipboard.
# Supports the common usage patterns that tmux-yank and other tools expect.
#   Read (stdout):  xclip -selection clipboard -o
#   Write (stdin):  xclip -selection clipboard

OUT=0
for arg in "$@"; do
    [ "$arg" = "-o" ] || [ "$arg" = "-out" ] && OUT=1
done

if [ "$OUT" -eq 1 ]; then
    powershell.exe -NoProfile -Command \
        "[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; Get-Clipboard" \
        2>/dev/null | tr -d '\r'
else
    clip.exe
fi
