commit 85aaec162665fac3f85b82d5f3fdbb826b1f4bc3 parent 7cb215c3f9f82dbe061667183111d4ff383aebd6 Author: Chris Down <chris@chrisdown.name> Date: Tue, 9 Jul 2019 22:28:26 +0100 clipmenud: Avoid deleting still-referenced files in the case of dupes Diffstat:
M | clipmenud | | | 13 | +++++++++++-- |
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/clipmenud b/clipmenud @@ -51,6 +51,10 @@ die() { exit "${1?}" } +make_line_cksums() { + while read -r line; do cksum <<< "${line#* }"; done +} + get_first_line() { # Args: # - $1, the file or data @@ -256,9 +260,14 @@ while true; do fi if (( CM_MAX_CLIPS )) && [[ -f $cache_file ]]; then + # comm filters out duplicate entries that we'd delete still + # referenced entries for mapfile -t to_remove < <( - head -n -"$CM_MAX_CLIPS" "$cache_file" | - while read -r line; do cksum <<< "${line#* }"; done + comm -23 \ + <(head -n -"$CM_MAX_CLIPS" "$cache_file" | + make_line_cksums | sort) \ + <(tail -n -"$CM_MAX_CLIPS" "$cache_file" | + make_line_cksums | sort) ) num_to_remove="${#to_remove[@]}" if (( num_to_remove )); then