#!/bin/sh
# alloy-clipstore — store a clipboard selection, unless it is a secret.
#
# What the sway config's two `wl-paste --watch` lines call instead of
# `cliphist store` directly. The read half is still alloy-clipmenu and the
# store is still cliphist's; this only decides whether an item reaches it.
#
# The rule is one line: if alloy-secret-copy left its sentinel, this selection
# is a password on its way to a paste and is not history. See that script for
# why a sentinel rather than the `x-kde-passwordManagerHint` MIME convention,
# and for the failure direction it is built around. GO alloy problem e7a9e38c.
#
# Consuming stdin on the skip path is deliberate. `wl-paste --watch` writes the
# selection to this process; exiting without reading it leaves the writer with
# a closed pipe and a SIGPIPE on the next selection, which is a broken watcher
# rather than a skipped item.

set -eu

sentinel="${XDG_RUNTIME_DIR:-/tmp}/alloy-secret-clipboard"

if [ -e "$sentinel" ]; then
    cat >/dev/null
    exit 0
fi

exec cliphist store
