2014-02-05 10:12:34 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-08-22 20:40:59 +02:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2015-04-12 19:51:46 +02:00
|
|
|
LC_COLLATE=C
|
|
|
|
|
2015-08-22 14:13:26 +02:00
|
|
|
# Some people copy/paste huge swathes of text that could slow down dmenu
|
|
|
|
line_length_limit=500
|
|
|
|
|
2014-02-05 10:12:34 +01:00
|
|
|
declare -A selections
|
2015-04-12 19:51:46 +02:00
|
|
|
ordered_selections=()
|
|
|
|
|
|
|
|
files=("/tmp/clipmenu.$USER/"*)
|
|
|
|
|
|
|
|
for (( i=${#files[@]}-1; i>=0; i-- )); do
|
|
|
|
file=${files[$i]}
|
2014-02-05 10:12:34 +01:00
|
|
|
|
2015-08-22 14:13:26 +02:00
|
|
|
first_line=$(sed -n '/./{p;q}' "$file" | cut -c1-"$line_length_limit")
|
2014-02-05 10:12:34 +01:00
|
|
|
|
|
|
|
lines=$(wc -l "$file")
|
|
|
|
lines=${lines%% *}
|
|
|
|
|
|
|
|
if (( lines > 1 )); then
|
|
|
|
first_line+=" ($lines lines)"
|
|
|
|
fi
|
|
|
|
|
2015-04-12 19:51:46 +02:00
|
|
|
ordered_selections+=("$first_line")
|
2014-02-05 10:12:34 +01:00
|
|
|
selections[$first_line]=$file
|
|
|
|
done
|
|
|
|
|
2015-04-12 19:51:46 +02:00
|
|
|
chosen_line=$(
|
2015-08-23 00:08:48 +02:00
|
|
|
printf '%s\n' "${ordered_selections[@]}" | awk '!x[$0]++' | dmenu -l 8 "$@"
|
2015-04-12 19:51:46 +02:00
|
|
|
)
|
2014-02-05 10:16:42 +01:00
|
|
|
|
|
|
|
[[ $chosen_line ]] || exit 1
|
|
|
|
|
2014-02-05 10:48:03 +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
|
2015-08-07 20:13:53 +02:00
|
|
|
xsel -i --"$selection" < "${selections[$chosen_line]}"
|
2015-02-08 18:36:06 +01:00
|
|
|
else
|
|
|
|
xclip -sel "$selection" < "${selections[$chosen_line]}"
|
|
|
|
fi
|
2014-02-05 10:48:03 +01:00
|
|
|
done
|