clipmenu

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

commit 0717e72a038b9fa1303f4ade2d3a393de2f9deda
parent d5a94491719c175cac5c75bc6fe4b3884eac9d21
Author: Chris Down <chris@chrisdown.name>
Date:   Fri,  7 Aug 2015 19:15:15 +0100

Merge tag '1.0.0'

Initial stable release

Diffstat:
Mclipmenu | 15+++++++++++++--
Mclipmenud | 11+++++++----
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clipmenu b/clipmenu @@ -1,10 +1,17 @@ #!/bin/bash +LC_COLLATE=C + dmenu_lines=${CLIPMENU_LINES-8} declare -A selections +ordered_selections=() + +files=("/tmp/clipmenu.$USER/"*) + +for (( i=${#files[@]}-1; i>=0; i-- )); do + file=${files[$i]} -for file in /tmp/clipmenu/*; do first_line=$(sed -n '/./{p;q}' "$file") lines=$(wc -l "$file") @@ -14,10 +21,14 @@ for file in /tmp/clipmenu/*; do first_line+=" ($lines lines)" fi + ordered_selections+=("$first_line") selections[$first_line]=$file done -chosen_line=$(printf '%s\n' "${!selections[@]}" | dmenu -l "$dmenu_lines" "$@") +chosen_line=$( + printf '%s\n' "${ordered_selections[@]}" | + awk '!x[$0]++' | dmenu -l "$dmenu_lines" "$@" +) [[ $chosen_line ]] || exit 1 diff --git a/clipmenud b/clipmenud @@ -1,7 +1,7 @@ #!/bin/bash -cache_dir=/tmp/clipmenu/ -mkdir -p "$cache_dir" +cache_dir=/tmp/clipmenu.$USER/ +mkdir -p -m0700 "$cache_dir" declare -A last_data @@ -13,9 +13,12 @@ while sleep 1; do data=$(xclip -o -sel "$selection"; printf x) fi + # We add and remove the x so that trailing newlines are not stripped. + # Otherwise, they would be stripped by the very nature of how POSIX + # defines command substitution. data=${data%x} - [[ $data ]] || continue + [[ $data == *[^[:blank:]]* ]] || continue [[ ${last_data[$selection]} == "$data" ]] && continue last_data[$selection]=$data @@ -23,6 +26,6 @@ while sleep 1; do md5=$(md5sum <<< "$data") md5=${md5%% *} - printf '%s' "$data" > "$cache_dir/$md5" + printf '%s' "$data" > "$cache_dir/$(LC_ALL=C date +%F-%H-%M-%S)-$md5" done done