#!/usr/bin/env bash # Read the most recent items from CopyQ and present them in a rofi menu. # # Converted to bash from # https://github.com/cjbassi/rofi-copyq/blob/master/rofi-copyq # CopyQ script to get all clipboard items as JSON copyq_script_getAll=' var result=[]; for ( var i = 0; i < size(); ++i ) { var obj = {}; obj.row = i; obj.mimetypes = str(read("?", i)).split("\n"); obj.mimetypes.pop(); obj.text = str(read(i)); result.push(obj); } JSON.stringify(result); ' # Get clipboard items from CopyQ json_arr=$(printf '%s' "$copyq_script_getAll" | copyq -) # Parse JSON and format items for rofi # Process each JSON object separately, replacing newlines within each item items=$(printf '%s' "$json_arr" | jq -r '.[] | .text | gsub("\n"; " ") | gsub(" +"; " ")') # Show rofi menu and get selected index title='rofi-copyq' selected_index=$(printf '%s' "$items" | rofi -dmenu -i -p "$title" -format i) # If user selected an item, select it in CopyQ if [ -n "$selected_index" ]; then echo "Selected item: $selected_index" copyq "select($selected_index);" fi