clipmenu-spmenu/clipmenu
Chris Down 66301f4f5f Remove ability to override default dmenu lines with CLIPMENU_LINES
If people want to use this, they can just pass `-l <n>` to clipmenu and it will
be passed through to dmenu. I've checked that passing `-l` twice works fine and
accepts the second passed `-l` optarg as the definitive one.
2015-08-22 23:11:12 +01:00

44 lines
924 B
Bash
Executable file

#!/bin/bash
shopt -s nullglob
LC_COLLATE=C
# Some people copy/paste huge swathes of text that could slow down dmenu
line_length_limit=500
declare -A selections
ordered_selections=()
files=("/tmp/clipmenu.$USER/"*)
for (( i=${#files[@]}-1; i>=0; i-- )); do
file=${files[$i]}
first_line=$(sed -n '/./{p;q}' "$file" | cut -c1-"$line_length_limit")
lines=$(wc -l "$file")
lines=${lines%% *}
if (( lines > 1 )); then
first_line+=" ($lines lines)"
fi
ordered_selections+=("$first_line")
selections[$first_line]=$file
done
chosen_line=$(
printf '%s\n' "${ordered_selections[@]}" | awk '!x[$0]++' | dmenu -l 8 "$@"
)
[[ $chosen_line ]] || exit 1
for selection in clipboard primary; do
if type -p xsel >/dev/null 2>&1; then
xsel -i --"$selection" < "${selections[$chosen_line]}"
else
xclip -sel "$selection" < "${selections[$chosen_line]}"
fi
done