Requirements: rofi
, xclip
, and xdotool
in an Xorg session
According to apt show rofi
, Rofi is a
window switcher, run dialog and dmenu replacement
I searched the internet and came across User scripts. One of the scripts listed there, Kaomoji Rofi is described as "a simple kaomoji picker". I took its code (which I don't fully understand) and modified it:
#!/bin/bash
selection=$(rofi -i -width 1000 -theme solarized -dmenu $@ < /home/dkb/Documents/snippets.txt)
kaomoji=$(echo $selection)
echo -n "$kaomoji" | xclip -selection clipboard
sleep 0.1
xdotool key shift+Insert
- Rofi doesn't feature word wrap and so having
-width 1000
or more is useful to see as much of the snippet contents because only one line is allotted to per snippet. Anything exceeding the width is represented by …
- if
-theme
isn't used, the default theme or the theme last chosen by using rofi-theme-selector
as described here will be used.
- The snippets are in a plain text file, one snippet per line. (Running
sort -u -o $HOME/Documents/snippets.txt $HOME/Documents/snippets.txt
once in a while keeps them sorted though it isn't really necessary.)
sleep 0.1
and xdotool key shift+Insert
are not essential. Users can use their preferred method to paste clipboard text.
I saved the script as rofi-snippets.sh in $HOME/bin
, made it executable, and bound it to Ctrl+` as the keyboard shortcut to launch it.
Users can rapidly select the snippet of their choice by typing in one or a few characters to highlight just the one snippet and then pressing Enter.
Here's an animation illustrating the script in action:
