#!/bin/sh
# alloy-clipmenu — pick something out of the clipboard history and copy it back.
#
# The read half of docs/STACK.md#clipboard-history. The sway config has run two
# `wl-paste --watch cliphist store` watchers since the stack landed, so the
# history was being filled from the first login and there was no way to get
# anything out of it: no bind, no picker, no verb. STACK.md named this exact
# pipeline ("cliphist list piped to a TUI picker") and it was never wired.
#
# cliphist list emits `<id>\t<preview>`; decode takes the id back to the real
# bytes, which is what makes this work for images and for text with newlines.

set -eu

cliphist list | fzf \
  --delimiter='\t' --with-nth=2.. \
  --prompt='paste ' --pointer='>' --marker=' ' \
  --layout=reverse --no-multi --no-sort --height=100% --border=none --info=inline \
  | cliphist decode \
  | wl-copy
