clipmenu #!/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 dmenu_lines=${CLIPMENU_LINES-8} 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[{{&blob}}]++' | dmenu -l "$dmenu_lines" "$@" ) [[ $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