clipmenu-spmenu/clipctl
Chris Down 84fd3614ab clipmenud: Allow disable with USR1 and enable with USR2
This allows avoiding having to delete after the fact for things like
issues #57 and #98.

Why have this over just stopping clipmenud? Well:

1. Stopping clipmenud should usually be an init system action, but we
   are init-system agnostic. If we just exit, we don't have a way of
   reliably starting again.
2. Even if we *do* do it using the init system, we don't want some
   things (like a lingering xsel which owns the selection for
   CM_OWN_CLIPBOARD) being killed as well.
3. This is a nicer interface for things like password managers to stop
   clipmenu rather than stopping clipmenu entirely.
2020-03-25 19:13:22 +00:00

28 lines
651 B
Bash
Executable file

#!/usr/bin/env bash
if [[ -z $1 ]] || [[ $1 == --help ]] || [[ $1 == -h ]]; then
cat << 'EOF'
clipctl provides controls for the clipmenud daemon.
You can temporarily disable clip collection without stopping clipmenud entirely
by running "clipctl disable". You can then reenable with "clipctl enable".
EOF
exit 0
fi
_CLIPMENUD_PID=$(pgrep -u "$(id -u)" -nf '.*/?clipmenud$')
if [[ -z "$_CLIPMENUD_PID" ]]; then
echo "clipmenud is not running"
exit 2
fi
case $1 in
enable) kill -USR2 "$_CLIPMENUD_PID" ;;
disable) kill -USR1 "$_CLIPMENUD_PID" ;;
*)
printf 'Unknown command: %s\n' "$1"
exit 1
;;
esac