clipmenud: Colocate related variables and comments

This commit is contained in:
Chris Down 2020-03-23 17:20:15 +00:00
parent 4770e52cf3
commit f8658b0d00

View file

@ -4,31 +4,25 @@
: "${CM_OWN_CLIPBOARD=0}" : "${CM_OWN_CLIPBOARD=0}"
: "${CM_DEBUG=0}" : "${CM_DEBUG=0}"
: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}" : "${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. # Buffer to batch to avoid calling too much. Only used if CM_MAX_CLIPS >0.
: "${CM_MAX_CLIPS=1000}"
CM_MAX_CLIPS_THRESH=$(( CM_MAX_CLIPS + 100 )) CM_MAX_CLIPS_THRESH=$(( CM_MAX_CLIPS + 100 ))
# Shellcheck is mistaken here, this is used later as lowercase.
# shellcheck disable=SC2153
: "${CM_SELECTIONS=clipboard primary}" : "${CM_SELECTIONS=clipboard primary}"
read -r -a selections <<< "$CM_SELECTIONS"
major_version=6 major_version=6
cache_dir=$CM_DIR/clipmenu.$major_version.$USER/ cache_dir=$CM_DIR/clipmenu.$major_version.$USER/
cache_file=$cache_dir/line_cache cache_file=$cache_dir/line_cache
# lock_file is the lock for *one* iteration of clipboard capture/propagation. # lock_file: lock for *one* iteration of clipboard capture/propagation
# session_lock_file is the lock to prevent multiple clipmenud daemons from # session_lock_file: lock to prevent multiple clipmenud daemons
# running at once.
lock_file=$cache_dir/lock lock_file=$cache_dir/lock
session_lock_file=$cache_dir/session_lock session_lock_file=$cache_dir/session_lock
lock_timeout=2 lock_timeout=2
has_xdotool=0 has_xdotool=0
# This comes from the environment, so we rely on word splitting.
# shellcheck disable=SC2206
cm_selections=( $CM_SELECTIONS )
if command -v timeout >/dev/null 2>&1; then if command -v timeout >/dev/null 2>&1; then
timeout_cmd=(timeout 1) timeout_cmd=(timeout 1)
else else
@ -133,7 +127,7 @@ while true; do
fi fi
fi fi
for selection in "${cm_selections[@]}"; do for selection in "${selections[@]}"; do
data=$(_xsel -o --"$selection"; printf x) data=$(_xsel -o --"$selection"; printf x)
data=${data%x} data=${data%x}
@ -163,17 +157,14 @@ while true; do
cache_file_output="$(date +%s%N) $first_line" cache_file_output="$(date +%s%N) $first_line"
filename="$cache_dir/$(cksum <<< "$first_line")" filename="$cache_dir/$(cksum <<< "$first_line")"
last_cache_file_output[$selection]=$cache_file_output
last_data[$selection]=$data last_data[$selection]=$data
debug "Writing $data to $filename" debug "Writing $data to $filename"
printf '%s' "$data" > "$filename" printf '%s' "$data" > "$filename"
debug "Writing $cache_file_output to $cache_file" debug "Writing $cache_file_output to $cache_file"
printf '%s\n' "$cache_file_output" >> "$cache_file" printf '%s\n' "$cache_file_output" >> "$cache_file"
last_cache_file_output[$selection]=$cache_file_output
if (( CM_OWN_CLIPBOARD )) && [[ $selection == clipboard ]]; then if (( CM_OWN_CLIPBOARD )) && [[ $selection == clipboard ]]; then
# Only clipboard, since apps like urxvt will unhilight for PRIMARY # Only clipboard, since apps like urxvt will unhilight for PRIMARY
_xsel -o --clipboard | _xsel -i --clipboard _xsel -o --clipboard | _xsel -i --clipboard