#!/usr/bin/env bash #------------------------------------------------------------------------------ # Path - /usr/bin/clipmenu-ctl # GitHub - https://github.com/The-Repo-Club/ # Author - The-Repo-Club [wayne6324@gmail.com] # Start On - Tue 05 Oct 16:32:27 BST 2021 # Modified On - Sun 31 Oct 00:32:27 BST 2021 #------------------------------------------------------------------------------ : "${CM_DIR:="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" if [[ -z $1 ]] || [[ $1 == --help ]] || [[ $1 == -h ]]; then cat << 'EOF' clipmenu-ctl provides controls for the clipmenu-daemon daemon. Commands: enable: enable clip collection disable: disable clip collection status: returns "enabled" or "disabled" toggle: toggles clip collection version: returns major version cache-dir: returns the directory used for caching EOF exit 0 fi clipmenu_daemon_pid=$(pgrep -u "$(id -u)" -nf 'clipmenu-daemon$') case $1 in enable|disable|toggle|status) if [[ -z "$clipmenu_daemon_pid" ]]; then echo "clipmenu-daemon is not running" >&2 exit 2 fi ;; esac major_version=6 cache_dir=$CM_DIR/clipmenu.$major_version.$USER status_file=$cache_dir/status case $1 in enable) kill -USR2 "$clipmenu_daemon_pid" ;; disable) kill -USR1 "$clipmenu_daemon_pid" ;; status) cat "$status_file" ;; toggle) if [ $(clipmenu-ctl status) == "enabled" ]; then clipmenu-ctl disable else clipmenu-ctl enable fi ;; version) echo "$major_version" ;; cache-dir) echo "$cache_dir" ;; *) printf 'Unknown command: %s\n' "$1" >&2 exit 1 ;; esac