Skip to content

Commit

Permalink
Sort selections by recency
Browse files Browse the repository at this point in the history
  • Loading branch information
cdown committed Apr 12, 2015
1 parent bbd9b65 commit 3d079ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions clipmenu
@@ -1,10 +1,17 @@
#!/bin/bash

LC_COLLATE=C

dmenu_lines=${CLIPMENU_LINES-8}

declare -A selections
ordered_selections=()

files=(/tmp/clipmenu/*)

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")
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion clipmenud
Expand Up @@ -23,6 +23,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

0 comments on commit 3d079ab

Please sign in to comment.