info "Received disable signal, suspending clipboard capture"
_CM_DISABLED=1
_CM_FIRST_DISABLE=1
echo "disabled" > "$status_file"
}
sig_enable() {
if ! (( _CM_DISABLED )); then
info "Received enable signal but we're not disabled, so doing nothing"
return
fi
# Still store the last data so we don't end up eventually putting it in the
# clipboard if it wasn't changed
for selection in "${selections[@]}"; do
data=$(_xsel -o --"$selection"; printf x)
last_data_sel[$selection]=${data%x}
done
info "Received enable signal, resuming clipboard capture"
_CM_DISABLED=0
echo "enabled" > "$status_file"
}
kill_background_jobs() {
# While we usually _are_, there are no guarantees that we're the process
# group leader. As such, all we can do is look at the pending jobs. Bash
# avoids a subshell here, so the job list is in the right shell.
local bg
bg=$(jobs -p)
# Don't log `kill' failures, since with KillMode=control-group, we're
# racing with init.
[[ $bg ]] && kill -- "$bg" 2>/dev/null
}
if [[ $1 == --help ]] || [[ $1 == -h ]]; then
cat << 'EOF'
clipmenud collects and caches what's on the clipboard. You can manage its
operation with clipmenu-ctl.
Environment variables:
- $CM_DEBUG: turn on debugging output (default: 0)
- $CM_DIR: specify the base directory to store the cache dir in (default: $XDG_RUNTIME_DIR, $TMPDIR, or /tmp)
- $CM_MAX_CLIPS: soft maximum number of clips to store, 0 for inf. At $CM_MAX_CLIPS + 10, the number of clips is reduced to $CM_MAX_CLIPS (default: 1000)
- $CM_ONESHOT: run once immediately, do not loop (default: 0)
- $CM_OWN_CLIPBOARD: take ownership of the clipboard. Note: this may cause missed copies if some other application also handles the clipboard directly (default: 0)
- $CM_SELECTIONS: space separated list of the selections to manage (default: "clipboard primary")
- $CM_SYNC_PRIMARY_TO_CLIPBOARD: sync selections from primary to clipboard immediately (default: 0)
- $CM_IGNORE_WINDOW: disable recording the clipboard in windows where the windowname matches the given regex (e.g. a password manager), do not ignore any windows if unset or empty (default: unset)
EOF
exit 0
fi
[[ $DISPLAY ]] || die 2 'The X display is unset, is your X server running?'
# It's ok that this only applies to the final directory.
# shellcheck disable=SC2174
mkdir -p -m0700 "$cache_dir"
echo "enabled" > "$status_file"
exec {session_lock_fd}> "$session_lock_file"
flock -x -n "$session_lock_fd" ||
die 2 "Can't lock session file -- is another clipmenud running?"