clipmenu-spmenu/clipmenu

29 lines
771 B
Plaintext
Raw Normal View History

#!/bin/bash
major_version=3
shopt -s nullglob
cache_dir=/tmp/clipmenu.$major_version.$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" | awk '!seen[$0]++' | dmenu -l 8 "$@")
[[ $chosen_line ]] || exit 1
file=$cache_dir/$(cksum <<< "$chosen_line")
if ! [[ -f "$file" ]]; then
2017-01-06 15:02:47 +01:00
# We didn't find this in cache
printf 'FATAL: %s not in cache\n' "$chosen_line" >&2
2017-01-06 15:02:47 +01:00
exit 2
fi
for selection in clipboard primary; do
xsel --logfile /dev/stderr -i --"$selection" < "$file"
done