commit e6c312b6394150384330c86a7c225030f96c1126 parent 8bb4ff39998b027b7f9a5c1e6ca9afe66c14ee03 Author: Chris Down <chris@chrisdown.name> Date: Tue, 24 Oct 2017 17:30:32 +0200 Avoid double writing if both selections are the same Diffstat:
M | clipmenud | | | 16 | +++++++++++----- |
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/clipmenud b/clipmenud @@ -116,12 +116,18 @@ while (( CM_ONESHOT )) || sleep "${CM_SLEEP:-0.5}"; do debug "New clipboard entry on $selection selection: \"$first_line\"" - filename="$cache_dir/$(cksum <<< "$first_line")" - debug "Writing $data to $filename" - printf '%s' "$data" > "$filename" + # Without checking ${last_data[any]}, we often double write since both + # selections get the same content + if [[ ${last_data[any]} != "$data" ]]; then + filename="$cache_dir/$(cksum <<< "$first_line")" + debug "Writing $data to $filename" + printf '%s' "$data" > "$filename" + + debug "Writing $first_line to $cache_file" + printf '%s\n' "$first_line" >> "$cache_file" + fi - debug "Writing $first_line to $cache_file" - printf '%s\n' "$first_line" >> "$cache_file" + last_data[any]=$data if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then # Take ownership of the clipboard, in case the original application