clipmenu

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

commit e65b51b33c6e219b05aab21c909da2a7b5e6dbdc
parent 117385015b98004cc359d18e5e3f7892e3aad0f8
Author: Chris Down <chris@chrisdown.name>
Date:   Sun, 19 Mar 2017 07:45:36 +0000

Use CM_* env vars

Diffstat:
MREADME.md | 4++--
Mclipmenu | 2+-
Mclipmenud | 14+++++++++-----
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md @@ -22,8 +22,8 @@ there, but it basically works like this: ## clipmenud 1. `clipmenud` polls the clipboard every 0.5 seconds (or another interval as - configured with the `CLIPMENUD_SLEEP` environment variable). Unfortunately - there's no interface to subscribe for changes in X11, so we must poll. + configured with the `CM_SLEEP` environment variable). Unfortunately there's + no interface to subscribe for changes in X11, so we must poll. 2. If `clipmenud` detects changes to the clipboard contents, it writes them out to the cache directory. diff --git a/clipmenu b/clipmenu @@ -7,7 +7,7 @@ shopt -s nullglob cache_dir=/tmp/clipmenu.$major_version.$USER cache_file=$cache_dir/line_cache -: "${CM_LAUNCHER:-dmenu}" +: "${CM_LAUNCHER=dmenu}" # It's okay to hardcode `-l 8` here as a sensible default without checking # whether `-l` is also in "$@", because the way that dmenu works allows a later diff --git a/clipmenud b/clipmenud @@ -6,6 +6,10 @@ cache_file=$cache_dir/line_cache lock_file=$cache_dir/lock lock_timeout=2 +: "${CM_ONESHOT=0}" +: "${CM_OWN_CLIPBOARD=1}" +: "${CM_DEBUG=0}" + _xsel() { timeout 1 xsel --logfile /dev/stderr "$@" } @@ -42,7 +46,7 @@ get_first_line() { } debug() { - if (( DEBUG )); then + if (( CM_DEBUG )); then printf '%s\n' "$@" >&2 fi } @@ -56,9 +60,9 @@ declare -A last_filename exec {lock_fd}> "$lock_file" -while sleep "${CLIPMENUD_SLEEP:-0.5}"; do +while sleep "${CM_SLEEP:-0.5}"; do if ! flock -x -w "$lock_timeout" "$lock_fd"; then - if (( ONESHOT )); then + if (( CM_ONESHOT )); then printf 'ERROR: %s\n' 'Timed out waiting for lock' >&2 exit 1 else @@ -114,7 +118,7 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do debug "Writing $first_line to $cache_file" printf '%s\n' "$first_line" >> "$cache_file" - if ! (( NO_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then + if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then # Take ownership of the clipboard, in case the original application # is unable to serve the clipboard request (due to being suspended, # etc). @@ -132,7 +136,7 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do flock -u "$lock_fd" - if (( ONESHOT )); then + if (( CM_ONESHOT )); then debug 'Oneshot mode enabled, exiting' break fi