clipmenu-spmenu/clipmenud
Chris Down 35521af0ec Make sure that the clipboard data is not just whitespace before copying
This avoids getting a bad array subscript, and polluting the menu.

Thanks to @kaihendry for noticing this issue and suggesting a fix. This commit
is a modified version of his suggestion, using [:blank:] instead of [:space:].

Closes #7.
2015-07-27 20:00:21 -07:00

29 lines
616 B
Bash
Executable file

#!/bin/bash
cache_dir=/tmp/clipmenu/
mkdir -p "$cache_dir"
declare -A last_data
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
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/$md5"
done
done