clipmenu

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

commit dc20b9c5baf932e9a033cdad1d5905dbe79116f4
parent 640e8a1fcf79053764742f5aa5e54c99e6f16ebb
Author: Jordan Galby <gravemind2a@gmail.com>
Date:   Sun, 28 Apr 2019 07:18:59 +0000

Fix clipdel cutting timestamps from line cache files (#94)

Clipdel `cut`ed the timestamp column from the line cache files.

For the end-user, it fixes clipdel apparently re-ordering clipmenu
entries.
Diffstat:
Mclipdel | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/clipdel b/clipdel @@ -47,6 +47,10 @@ fi raw_pattern=$1 esc_pattern=${raw_pattern//\#/'\#'} +# We use 2 separate sed commands so "esc_pattern" matches only the 'clip' text +# without the timestamp (e.g. $> clipdel '^delete_exact_match$') +sed_common_command="s#^[0-9]\+ ##;\\#${esc_pattern}#" + if ! [[ $raw_pattern ]]; then printf '%s\n' 'No pattern provided, see --help' >&2 exit 2 @@ -60,8 +64,8 @@ if (( CM_REAL_DELETE )) && [[ "$raw_pattern" == ".*" ]]; then exit 0 else mapfile -t matches < <( - cat "${line_cache_files[@]}" | cut -d' ' -f2- | sort -u | - sed -n "\\#${esc_pattern}#p" + sed -n "${sed_common_command}p" "${line_cache_files[@]}" | + sort -u ) if (( CM_REAL_DELETE )); then @@ -74,7 +78,11 @@ else for file in "${line_cache_files[@]}"; do temp=$(mktemp) - cut -d' ' -f2- < "$file" | sed "\\#${esc_pattern}#d" > "$temp" + # sed 'h' and 'g' here means save and restore the line, so + # timestamps are not removed from non-deleted lines. 'd' deletes the + # line and restarts, skipping 'g'/restore. + # https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands + sed "h;${sed_common_command}d;g" "$file" > "$temp" mv -- "$temp" "$file" done