#!/bin/bash


#         ___      __   _     __        __ 
#    ____/ (_)__  / /  (_)__ / /_  ___ / / 
#   / __/ / / _ \/ _ \/ (_-</ __/ (_-</ _ \
#   \__/_/_/ .__/_//_/_/___/\__(_)___/_//_/
#         /_/                              


set -euo pipefail

if [[ $# -eq 0 ]]; then
  echo "Usage: ${0##*/} [d|w|*]"
  echo "d: Delete the selected entry from the clipboard history."
  echo "w: Wipe the clipboard history."
  echo "*: Decode the selected entry and copy it to the clipboard."
  exit 1
fi

case $1 in
  d)  cliphist list | rofi -dmenu -replace | cliphist delete
      notify-send "Selected entry deleted from history"
      ;;
  w)  if [ "$(echo -e "Clear\nCancel" | rofi -dmenu)" == "Clear" ]; then
        cliphist wipe
        notify-send "Clipboard history cleared"
      fi
      ;;
  *)  cliphist list | rofi -dmenu -replace | cliphist decode | wl-copy
      notify-send "Selected entry copy to clipboard"
      ;;
esac
