clipmenu-spmenu/clipmenu
Chris Down 8885306970 perf: Don't use date, use CRC instead
We don't need to sort by date now that we record in $cache_file, which
does it naturally for us.
2017-01-06 14:53:59 +00:00

32 lines
828 B
Bash
Executable file

#!/bin/bash
shopt -s nullglob
cache_dir=/tmp/clipmenu.$USER
cache_file=$cache_dir/line_cache
# It's okay to hardcode `-l 8` here as a sensible default without checking
# whether `-l` is also in "$@", because the way that dmenu works allows a later
# argument to override an earlier one. That is, if the user passes in `-l`, our
# one will be ignored.
chosen_line=$(tac "$cache_file" | uniq | dmenu -l 8 "$@")
[[ $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, run clipmenu-fsck\n' "$chosen_line" >&2
exit 2
fi
for selection in clipboard primary; do
if type -p xsel >/dev/null 2>&1; then
xsel -i --"$selection" < "$file"
else
xclip -sel "$selection" < "$file"
fi
done