72e15005e9
This is configurable via an environment variable rather than a command line option, as I'm not expecting many people really need to change this thing. I profiled the change from 1 -> 0.5 seconds on an old P4, and saw pretty much no difference in CPU usage, whether there were new clipboard entries or not. Closes #12.
32 lines
877 B
Bash
Executable file
32 lines
877 B
Bash
Executable file
#!/bin/bash
|
|
|
|
cache_dir=/tmp/clipmenu.$USER/
|
|
mkdir -p -m0700 "$cache_dir"
|
|
|
|
declare -A last_data
|
|
|
|
while sleep "${CLIPMENUD_SLEEP:-0.5}"; do
|
|
for selection in clipboard primary; do
|
|
if type -p xsel >/dev/null 2>&1; then
|
|
data=$(xsel --"$selection"; printf x)
|
|
else
|
|
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 == *[^[:blank:]]* ]] || continue
|
|
|
|
[[ ${last_data[$selection]} == "$data" ]] && continue
|
|
last_data[$selection]=$data
|
|
|
|
md5=$(md5sum <<< "$data")
|
|
md5=${md5%% *}
|
|
|
|
printf '%s' "$data" > "$cache_dir/$(LC_ALL=C date +%F-%H-%M-%S)-$md5"
|
|
done
|
|
done
|