clipmenu

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

commit 17823baceadb2d97c0a79ad223c1d5980dc21db0
parent 25219b787c07050ed1de59a9925ae4380413f5d1
Author: Axel Dahlberg <axel.dahlberg12@gmail.com>
Date:   Thu, 21 Jan 2021 16:15:00 +0100

Added commands to clipctl to check the status, toggle, get version and directory (#152)


Diffstat:
Mclipctl | 43++++++++++++++++++++++++++++++++++---------
Mclipdel | 5+----
Mclipfsck | 6+-----
Mclipmenu | 5+----
Mclipmenud | 8+++++---
Mtests/test-clipmenu | 5+----
Mtests/test-perf | 6+-----
7 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/clipctl b/clipctl @@ -1,25 +1,50 @@ #!/usr/bin/env bash +: "${CM_DIR:="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" + 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". +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 -_CLIPMENUD_PID=$(pgrep -u "$(id -u)" -nf 'clipmenud$') +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|disable|toggle|status) + if [[ -z "$clipmenud_pid" ]]; then + echo "clipmenud is not running" + 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 "$_CLIPMENUD_PID" ;; - disable) kill -USR1 "$_CLIPMENUD_PID" ;; + enable) kill -USR2 "$clipmenud_pid" ;; + disable) kill -USR1 "$clipmenud_pid" ;; + status) cat "$status_file" ;; + toggle) + if [[ $(clipctl status) == "enabled" ]]; then + clipctl disable + else + clipctl enable + fi + ;; + version) echo "$major_version" ;; + cache-dir) echo "$cache_dir" ;; *) printf 'Unknown command: %s\n' "$1" exit 1 diff --git a/clipdel b/clipdel @@ -1,17 +1,14 @@ #!/usr/bin/env bash -: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" CM_REAL_DELETE=0 if [[ $1 == -d ]]; then CM_REAL_DELETE=1 shift fi -major_version=6 - shopt -s nullglob -cache_dir=$CM_DIR/clipmenu.$major_version.$USER +cache_dir=$(clipctl cache-dir) cache_file=$cache_dir/line_cache lock_file=$cache_dir/lock lock_timeout=2 diff --git a/clipfsck b/clipfsck @@ -1,12 +1,8 @@ #!/usr/bin/env bash -: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" - -major_version=6 - shopt -s nullglob -cache_dir=$CM_DIR/clipmenu.$major_version.$USER +cache_dir=$(clipctl cache-dir) cache_file=$cache_dir/line_cache declare -A cksums diff --git a/clipmenu b/clipmenu @@ -1,14 +1,11 @@ #!/usr/bin/env bash : "${CM_LAUNCHER=dmenu}" -: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" : "${CM_HISTLENGTH=8}" -major_version=6 - shopt -s nullglob -cache_dir=$CM_DIR/clipmenu.$major_version.$USER +cache_dir=$(clipctl cache-dir) cache_file=$cache_dir/line_cache # Not -h, see #142 diff --git a/clipmenud b/clipmenud @@ -4,7 +4,6 @@ : "${CM_OWN_CLIPBOARD=0}" : "${CM_SYNC_PRIMARY_TO_CLIPBOARD=0}" : "${CM_DEBUG=0}" -: "${CM_DIR:="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" : "${CM_MAX_CLIPS:=1000}" # Buffer to batch to avoid calling too much. Only used if CM_MAX_CLIPS >0. @@ -13,9 +12,10 @@ CM_MAX_CLIPS_THRESH=$(( CM_MAX_CLIPS + 10 )) : "${CM_SELECTIONS:=clipboard primary}" read -r -a selections <<< "$CM_SELECTIONS" -major_version=6 -cache_dir=$CM_DIR/clipmenu.$major_version.$USER/ +cache_dir=$(clipctl cache-dir) cache_file=$cache_dir/line_cache +status_file=$cache_dir/status +echo "enabled" > "$status_file" # lock_file: lock for *one* iteration of clipboard capture/propagation # session_lock_file: lock to prevent multiple clipmenud daemons @@ -60,6 +60,7 @@ sig_disable() { info "Received disable signal, suspending clipboard capture" _CM_DISABLED=1 _CM_FIRST_DISABLE=1 + echo "disabled" > "$status_file" [[ -v _CM_CLIPNOTIFY_PID ]] && kill "$_CM_CLIPNOTIFY_PID" } @@ -78,6 +79,7 @@ sig_enable() { info "Received enable signal, resuming clipboard capture" _CM_DISABLED=0 + echo "enabled" > "$status_file" } kill_background_jobs() { diff --git a/tests/test-clipmenu b/tests/test-clipmenu @@ -4,10 +4,7 @@ set -x set -e set -o pipefail -: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" - -major_version=6 -dir=$CM_DIR/clipmenu.$major_version.$USER +dir=$(clipctl cache-dir) cache_file=$dir/line_cache if [[ $0 == /* ]]; then diff --git a/tests/test-perf b/tests/test-perf @@ -1,14 +1,10 @@ #!/usr/bin/env bash -major_version=6 - msg() { printf '>>> %s\n' "$@" >&2 } -: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" - -dir=$CM_DIR/clipmenu.$major_version.$USER +dir=$(clipctl cache-dir) cache_file=$dir/line_cache log=$(mktemp)