This is the fifth in a series of several posts on how to do way more than you really need to with rofi
. It’s a neat little tool that does so many cool things. I don’t have a set number of posts, and I don’t have a set goal. I just want to share something I find useful.
This post looks at configuring rofi
’s matching and sorting.
- Assumptions
- Code
- Overview
- Basic Sort Config
- (Yet Another)
rofi
Options Script - Change Matching and Sorting Via a
modi
Assumptions
I’m running Fedora 27. Most of the instructions are based on that OS. This will translate fairly well to other RHEL derivatives. The Debian ecosystem should also work fairly well, albeit with totally different package names. This probably won’t work at all on Windows, and I have no intention of fixing that.
You’re going to need a newer version of rofi
, >=1.4
. I’m currently running this:
$ rofi -version |
If you installed from source, you should be good to go.
Code
You can view the code related to this post under the post-05-matching-and-sorting
tag.
Overview
For the most part, rofi
sorts via Levenshtein distance. In a nutshell, the Levenshtein distance counts the number of changes necessary to go from one string to another. You can view rofi
’s implementation. It’s utf-8
-aware, which is very nice.
When running fuzzy
matches, rofi
can also sort via FZF. Viewing its implementation of FZF might be useful. I believe it too is utf-8
-aware.
As for the other matching methods, they seem to be vanilla. While there can be fairly substantial differences in regex
and glob
implementations across different languages, I haven’t been negatively affected by rofi
’s spin yet (I’ve been too busy writing other things to really delve deep). rofi
’s going to be better sometimes and worse other times. Using the Levenshtein distance makes things pretty easy to use.
Comparison
I’ve made a quick chart to (quite briefly) highlight the differences. I just looked at sorting, Levenshtein distance, and fuzzy
matching. regex
and glob
matching are too specialized to easily throw in a simple chart like this.
I used this script to compile all the information (plus a bunch more).
generate-matching-and-sorting-comparison | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #!/bin/bash |
Basic Sort Config
Personally, I find it useful to have things at least minimally sorted as I’m going.
$ sed \ |
--- $XDG_USER_CONFIG_DIR/rofi/config.rasi.bak |
However, the matching
method is very much situational. normal
should work most of the time. fuzzy
might be better, but I don’t have any metrics so I’m not sure how it affects performance and all that. glob
is amazing when moving files around, but might not be very useful when attempting to drun
. You could always run regex
but then no one else would want to read your scripts and you’d turn to a life of blogging like me.
(Yet Another) rofi
Options Script
I slapped together a quick script to handle matching and sorting.
$ scripts/configure-matching-and-sorting -h |
I tried to make this easy. To use the existing config, just add the pertinent flag.
$ scripts/configure-matching-and-sorting -m -s -l |
--- $XDG_USER_CONFIG_DIR/rofi/config.rasi.bak |
While it looks like that did something, it just uncommented the defaults. It didn’t actually change anything.
To actually change something, you can either feed it in via the command or leave off the flag and feed it in via the GUI.
$ scripts/configure-matching-and-sorting -o matching -m fuzzy |
--- $XDG_USER_CONFIG_DIR/rofi/config.rasi.bak |
$ scripts/configure-matching-and-sorting -o matching |
--- $XDG_USER_CONFIG_DIR/rofi/config.rasi.bak |
Full Script
configure-matching-and-sorting | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | #!/usr/bin/env python |
Change Matching and Sorting Via a modi
After the last post’s modi
, I wanted to see if I could repeat something similar here. This script is still pretty raw, but it gets the job done. Total GUI, like before.
rofi-tweak-sort | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | #!/usr/bin/env python |
As before, I’d recommend actually installing this to a common location.
$ mkdir -p $XDG_USER_CONFIG_DIR/rofi/scripts |