Use CM_* env vars

This commit is contained in:
Chris Down 2017-03-19 07:45:36 +00:00
parent 117385015b
commit e65b51b33c
3 changed files with 12 additions and 8 deletions

View file

@ -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.

View file

@ -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

View file

@ -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