2014-02-05 09:57:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-07-28 05:01:41 +02:00
|
|
|
cache_dir=/tmp/clipmenu.$USER/
|
2015-07-28 05:16:13 +02:00
|
|
|
mkdir -p -m0700 "$cache_dir"
|
2014-02-05 09:57:11 +01:00
|
|
|
|
2014-02-05 11:51:48 +01:00
|
|
|
declare -A last_data
|
|
|
|
|
2015-09-06 02:43:38 +02:00
|
|
|
while sleep "${CLIPMENUD_SLEEP:-0.5}"; do
|
2014-02-05 10:45:23 +01:00
|
|
|
for selection in clipboard primary; do
|
2015-02-08 18:36:06 +01:00
|
|
|
if type -p xsel >/dev/null 2>&1; then
|
|
|
|
data=$(xsel --"$selection"; printf x)
|
2015-09-11 22:29:14 +02:00
|
|
|
xsel --"$selection" | xsel -i --"$selection"
|
2015-02-08 18:36:06 +01:00
|
|
|
else
|
|
|
|
data=$(xclip -o -sel "$selection"; printf x)
|
2015-09-11 22:29:14 +02:00
|
|
|
xclip -o -sel "$selection" | xclip -i -sel "$selection"
|
2015-02-08 18:36:06 +01:00
|
|
|
fi
|
|
|
|
|
2015-07-28 05:19:41 +02:00
|
|
|
# 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.
|
2014-02-05 10:45:23 +01:00
|
|
|
data=${data%x}
|
2014-02-05 11:02:39 +01:00
|
|
|
|
2015-07-28 04:58:05 +02:00
|
|
|
[[ $data == *[^[:blank:]]* ]] || continue
|
2014-02-05 11:02:39 +01:00
|
|
|
|
2014-02-05 11:51:48 +01:00
|
|
|
[[ ${last_data[$selection]} == "$data" ]] && continue
|
|
|
|
last_data[$selection]=$data
|
|
|
|
|
2014-02-05 10:45:23 +01:00
|
|
|
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"
|
2014-02-05 10:45:23 +01:00
|
|
|
done
|
2014-02-05 09:57:11 +01:00
|
|
|
done
|