Avoid double writing if both selections are the same

This commit is contained in:
Chris Down 2017-10-24 17:30:32 +02:00
parent 8bb4ff3999
commit e6c312b639

View file

@ -116,12 +116,18 @@ while (( CM_ONESHOT )) || sleep "${CM_SLEEP:-0.5}"; do
debug "New clipboard entry on $selection selection: \"$first_line\"" debug "New clipboard entry on $selection selection: \"$first_line\""
# 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")" filename="$cache_dir/$(cksum <<< "$first_line")"
debug "Writing $data to $filename" debug "Writing $data to $filename"
printf '%s' "$data" > "$filename" printf '%s' "$data" > "$filename"
debug "Writing $first_line to $cache_file" debug "Writing $first_line to $cache_file"
printf '%s\n' "$first_line" >> "$cache_file" printf '%s\n' "$first_line" >> "$cache_file"
fi
last_data[any]=$data
if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then
# Take ownership of the clipboard, in case the original application # Take ownership of the clipboard, in case the original application