#!/usr/bin/env bash set -euo pipefail state_dir="${XDG_CACHE_HOME:-$HOME/.cache}" mkdir -p "$state_dir" 2>/dev/null || true if [ ! -w "$state_dir" ]; then state_dir="/tmp" fi history_file="$state_dir/polybar-clipboard-history" export DISPLAY="${DISPLAY:-:0}" if [ -z "${XAUTHORITY:-}" ] && [ -r "$HOME/.Xauthority" ]; then export XAUTHORITY="$HOME/.Xauthority" fi current="" if command -v xclip >/dev/null 2>&1; then current="$(xclip -selection clipboard -o 2>/dev/null || true)" elif command -v xsel >/dev/null 2>&1; then current="$(xsel --clipboard --output 2>/dev/null || true)" fi if [ -n "$current" ]; then one_line="$(printf '%s' "$current" | tr '\n' ' ' | cut -c 1-180)" if ! grep -Fxq "$one_line" "$history_file" 2>/dev/null; then tmp="${history_file}.tmp" { printf '%s\n' "$one_line"; cat "$history_file" 2>/dev/null; } | awk 'NF && !seen[$0]++' | head -n 50 >"$tmp" mv "$tmp" "$history_file" fi fi choice="$( dmenu -i -p clipboard \ -fn "FiraCode Nerd Font-14" \ -nb "#282828" -nf "#ebdbb2" \ -sb "#d79921" -sf "#282828" <"$history_file" )" [ -n "$choice" ] || exit 0 if command -v xclip >/dev/null 2>&1; then printf '%s' "$choice" | xclip -selection clipboard elif command -v xsel >/dev/null 2>&1; then printf '%s' "$choice" | xsel --clipboard --input fi