#!/usr/bin/sh # @author nate zhou # @since 2025,2026 # clipboard manager for Wayland and X # @depends wmenu dmenu(xorg) wl-copy cliphist clipmenu(xorg) # This script has completions: `.config/{z,ba}sh/completions/_scripts.{z,ba}sh` usage() { cat << _EOF_ USAGE $(basename $0) [OPTION] clipboard manager for Wayland and X without any options, open the dynamic menu to choose a history entry OPTIONS -w,--wipe wipe the current session's clipboard history, cliphist in Wayland, climenu in X -h,--help print this usage manual _EOF_ exit 0 } set_variables() { if [ "$XDG_SESSION_TYPE" = "wayland" ]; then menu="${HOME}/.local/bin/wmenu-color" wipe_cmd="cliphist wipe" elif [ -n "$XAUTHORITY" ]; then menu="dmenu" wipe_cmd="rm -rf ${XDG_RUNTIME_DIR}/clipmenu.*.*/*" fi } wipe_history() { set_variables choice="$(printf "no\nyes" \ | $menu -p "$(basename $0): wipe clipboard history?")" if [ "$choice" = "yes" ]; then notify-send -u low -r 199 "$(basename $0)" "Clipboard wiped" $wipe_cmd else notify-send -u low -r 199 "$(basename $0)" "Aboarted"; exit 0 fi } open_clipboard() { if [ "$XDG_SESSION_TYPE" = "wayland" ]; then cliphist list | wmenu-color -p "$(basename $0)" -l 6 \ | cliphist decode \ | wl-copy elif [ -n "$XAUTHORITY" ]; then clipmenu fi } [ -z "$1" ] && open_clipboard case "$1" in -w|--wipe) wipe_history ;; *) usage ;; esac