clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

clipctl (1249B)


      1#!/usr/bin/env bash
      2
      3: "${CM_DIR:="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
      4
      5if [[ -z $1 ]] || [[ $1 == --help ]] || [[ $1 == -h ]]; then
      6    cat << 'EOF'
      7clipctl provides controls for the clipmenud daemon.
      8
      9Commands:
     10    enable: enable clip collection
     11    disable: disable clip collection
     12    status: returns "enabled" or "disabled"
     13    toggle: toggles clip collection
     14    version: returns major version
     15    cache-dir: returns the directory used for caching
     16EOF
     17    exit 0
     18fi
     19
     20clipmenud_pid=$(pgrep -u "$(id -u)" -nf 'clipmenud$')
     21
     22case $1 in
     23    enable|disable|toggle|status)
     24        if [[ -z "$clipmenud_pid" ]]; then
     25            echo "clipmenud is not running" >&2
     26            exit 2
     27        fi
     28        ;;
     29esac
     30
     31major_version=6
     32cache_dir=$CM_DIR/clipmenu.$major_version.$USER
     33status_file=$cache_dir/status
     34
     35case $1 in
     36    enable) kill -USR2 "$clipmenud_pid" ;;
     37    disable) kill -USR1 "$clipmenud_pid" ;;
     38    status) cat "$status_file" ;;
     39    toggle)
     40        if [[ $(clipctl status) == "enabled" ]]; then
     41            clipctl disable
     42        else
     43            clipctl enable
     44        fi
     45    ;;
     46    version) echo "$major_version" ;;
     47    cache-dir) echo "$cache_dir" ;;
     48    *)
     49        printf 'Unknown command: %s\n' "$1" >&2
     50        exit 1
     51    ;;
     52esac