clipmenu

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

commit 74c479fa2fa09d1272c29b93e0528cd85d0c48e9
parent a3f0897aee7b1ebe590260dc51a46999367c95e9
Author: Matthew White <mehw.is.me@inventati.org>
Date:   Thu, 18 Nov 2021 00:19:23 +0000

clipdel: allow ".*" to print the cache directory to be deleted

Before doing an irreversible action via the option -d, allow the
pattern ".*" to print which cache directory will be deleted.

Diffstat:
Mclipdel | 30++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clipdel b/clipdel @@ -53,22 +53,24 @@ sed_common_command="s#^[0-9]\+ ##;\\#${esc_pattern}#" if ! [[ $raw_pattern ]]; then printf '%s\n' 'No pattern provided, see --help' >&2 exit 2 -fi - -exec {lock_fd}> "$lock_file" - -if (( CM_REAL_DELETE )) && [[ "$raw_pattern" == ".*" ]]; then - flock -x -w "$lock_timeout" "$lock_fd" || exit - rm -rf -- "$cache_dir" - mkdir -p -- "$cache_dir" - exit 0 +elif [[ "$raw_pattern" == ".*" ]]; then + delete_cache_dir=1 else mapfile -t matches < <( sed -n "${sed_common_command}p" "$cache_file" | sort -u ) +fi - if (( CM_REAL_DELETE )); then +exec {lock_fd}> "$lock_file" + +if (( CM_REAL_DELETE )); then + if (( delete_cache_dir )); then + flock -x -w "$lock_timeout" "$lock_fd" || exit + rm -rf -- "$cache_dir" + mkdir -p -- "$cache_dir" + exit 0 + else flock -x -w "$lock_timeout" "$lock_fd" || exit for match in "${matches[@]}"; do @@ -85,9 +87,9 @@ else mv -- "$temp" "$cache_file" flock -u "$lock_fd" - else - if (( ${#matches[@]} )); then - printf '%s\n' "${matches[@]}" - fi fi +elif (( delete_cache_dir )); then + printf 'delete cache dir: %s\n' "$cache_dir" +elif (( ${#matches[@]} )); then + printf '%s\n' "${matches[@]}" fi