clipmenu-spmenu/clipmenud

32 lines
853 B
Plaintext
Raw Normal View History

2014-02-05 09:57:11 +01:00
#!/bin/bash
cache_dir=/tmp/clipmenu.$USER/
mkdir -p -m0700 "$cache_dir"
2014-02-05 09:57:11 +01:00
declare -A last_data
2014-02-05 09:57:11 +01:00
while sleep 1; 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%% *}
2015-04-12 19:51:46 +02:00
printf '%s' "$data" > "$cache_dir/$(LC_ALL=C date +%F-%H-%M-%S)-$md5"
done
2014-02-05 09:57:11 +01:00
done