clipmenu #!/bin/bash LC_COLLATE=C 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") 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 "$@" ) [[ $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