clipmenu

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

commit bcbe7b144598db4a103f14e8408c4b7327d6d5e1
parent 940bd8e963ed17dcb9caf5ac809a70161bfdf107
Author: Chris Down <chris@chrisdown.name>
Date:   Tue, 24 Mar 2020 17:39:33 +0000

Merge branch 'release/6.0.1'

Diffstat:
Mclipmenu | 30+++++++-----------------------
Mclipmenud | 20++++++++++----------
2 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/clipmenu b/clipmenu @@ -27,43 +27,27 @@ EOF exit 0 fi -if [[ "$CM_LAUNCHER" == rofi ]]; then - # rofi supports dmenu-like arguments through the -dmenu flag - set -- -dmenu "$@" -fi +# rofi supports dmenu-like arguments through the -dmenu flag +[[ "$CM_LAUNCHER" == rofi ]] && set -- -dmenu "$@" list_clips() { LC_ALL=C sort -rnk 1 < "$cache_file" | cut -d' ' -f2- | awk '!seen[$0]++' } if [[ "$CM_LAUNCHER" == rofi-script ]]; then - if ! (( $# )); then + if (( $# )); then + chosen_line="${!#}" + else list_clips exit - else - # https://github.com/koalaman/shellcheck/issues/1141 - # shellcheck disable=SC2124 - chosen_line="${@: -1}" fi else - chosen_line=$( - list_clips | "$CM_LAUNCHER" -l "${CM_HISTLENGTH}" "$@" - ) + chosen_line=$(list_clips | "$CM_LAUNCHER" -l "${CM_HISTLENGTH}" "$@") fi [[ $chosen_line ]] || exit 1 - file=$cache_dir/$(cksum <<< "$chosen_line") - -if ! [[ -f "$file" ]]; then - # We didn't find this in cache - printf 'FATAL: %s not in cache (%s missing)\n' "$chosen_line" "$file" >&2 - printf 'Please report the following debug information:\n\n' >&2 - wc -l "$cache_file" >&2 - grep -nFR "$chosen_line" "$cache_dir" >&2 - stat "$file" >&2 - exit 2 -fi +[[ -f "$file" ]] || exit 2 for selection in clipboard primary; do xsel --logfile /dev/null -i --"$selection" < "$file" diff --git a/clipmenud b/clipmenud @@ -81,8 +81,7 @@ exec {session_lock_fd}> "$session_lock_file" flock -x -n "$session_lock_fd" || die 2 "Can't lock session file -- is another clipmenud running?" -declare -A last_data -declare -A last_cache_file_output +declare -A last_data_sel command -v clipnotify >/dev/null 2>&1 || die 2 "clipnotify not in PATH" command -v xdotool >/dev/null 2>&1 && has_xdotool=1 @@ -118,15 +117,15 @@ while true; do data=${data%x} # avoid trailing newlines being stripped [[ $data == *[^[:space:]]* ]] || continue - [[ ${last_data[$selection]} == "$data" ]] && continue + [[ $last_data == "$data" ]] && continue + [[ ${last_data_sel[$selection]} == "$data" ]] && continue - possible_partial=${last_data[$selection]} - if [[ $possible_partial && $data == "$possible_partial"* ]] || - [[ $possible_partial && $data == *"$possible_partial" ]]; then + if [[ $last_data && $data == "$last_data"* ]] || + [[ $last_data && $data == *"$last_data" ]]; then # Don't actually remove the file yet, because it might be # referenced by an older entry. These will be dealt with at vacuum. - debug "$selection: $possible_partial is a possible partial of $data" - previous_size=$(wc -c <<< "${last_cache_file_output[$selection]}") + debug "$selection: $last_data is a possible partial of $data" + previous_size=$(wc -c <<< "$last_cache_file_output") truncate -s -"$previous_size" "$cache_file" fi @@ -135,8 +134,9 @@ while true; do cache_file_output="$(date +%s%N) $first_line" filename="$cache_dir/$(cksum <<< "$first_line")" - last_cache_file_output[$selection]=$cache_file_output - last_data[$selection]=$data + last_cache_file_output=$cache_file_output + last_data=$data + last_data_sel[$selection]=$data debug "Writing $data to $filename" printf '%s' "$data" > "$filename"