clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 4e969bd67dc008fe82b309a3d8a4f924bf274421
parent 1896ceaccc921100da04744845eb17bfa23554d6
Author: Chris Down <chris@chrisdown.name>
Date:   Tue, 20 Feb 2018 11:03:35 +0000

Truncate cache file on duplicate

Diffstat:
Mclipmenud | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -104,6 +104,8 @@ fi mkdir -p -m0700 "$cache_dir" declare -A last_data +declare -A last_filename +declare -A last_cache_file_output command -v clipnotify >/dev/null 2>&1 && has_clipnotify=1 @@ -139,6 +141,7 @@ while true; do fi for selection in "${cm_selections[@]}"; do + cache_file=${cache_file_prefix}_$selection data=$(_xsel -o --"$selection"; printf x) debug "Data before stripping: $data" @@ -160,6 +163,7 @@ while true; do continue fi + # If we were in the middle of doing a selection when the previous poll # ran, then we may have got a partial clip. possible_partial=${last_data[$selection]} @@ -167,29 +171,34 @@ while true; do [[ $possible_partial && $data == *"$possible_partial" ]]; then debug "$possible_partial is a possible partial of $data" debug "Removing ${last_filename[$selection]}" + + previous_size=$(wc -c <<< "${last_cache_file_output[$selection]}") + truncate -s -"$previous_size" "$cache_file" + rm -- "${last_filename[$selection]}" fi last_data[$selection]=$data + last_filename[$selection]=$filename first_line=$(get_first_line "$data") debug "New clipboard entry on $selection selection: \"$first_line\"" - cache_file=${cache_file_prefix}_$selection - # Without checking ${last_data[any]}, we often double write since both # selections get the same content + cache_file_output="$(date +%s) $first_line" 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 '%d %s\n' "$(date +%s)" "$first_line" >> "$cache_file" + debug "Writing $cache_file_output to $cache_file" + printf '%s\n' "$cache_file_output" >> "$cache_file" fi last_data[any]=$data + last_cache_file_output[$selection]=$cache_file_output if (( CM_OWN_CLIPBOARD )) && [[ $selection != primary ]] && element_in clipboard "${cm_selections[@]}"; then