Retiring snippits
A while ago, I wrote Snippits, a Ruby program that performed text expansion, with quite a few useful features. I built is fairly quickly, because I had an itch to scratch: I hated typing the same thing over and over and over. Computers ought to be able to automate common tasks, and they can’t figure out how to do so themselves, we should be able to teach them. At the time, there was nothing that did text replacement on Linux (but several tools for Mac and Windows existed), so I set out to write my own.
I got pretty far - Snippits was functional, stable, and speedy enough to use daily, and I did so. Of course, it could have been more functional, more stable, and more speedy, but it was good enough for me - and, actually, a couple of users. I was proud of how Snippits had helped people, and I enjoyed using it immensely - there is something extremely satisfying to bypassing tedious typing and retyping of your name, address, email, or really, anything, over and over.
But, Snippits had a deep and underlying flaw to it’s design. I could not figure out how to detect text typed directly from Ruby (and I didn’t exactly want to drop down to C, and/or mess with XLib). the only tool I had available to me was xte, from the xautomation suite. It allowed me to generate arbitrary X key events, so, I designed a overly-complicated way at getting text: when Snippits was invoked via a hotkey, it would issue a Ctrl+Shift+Left, to select back a word, then Ctrl+X, to cut the text. It would then read the clipboard, look up an expansion (or attempt spelling autocorrection if it couldn’t find any) and type the result back.
This solution, while functional, was incredibly fragile. Keystrokes in the middle of the process might have strange effects, an application switching into focus might result in unintended behavior, and if those shortcuts weren’t defined for your application (such as a terminal emulator), the whole thing simply wouldn’t work. The whole process was also a lot slower than I would have liked. Sometimes, it would fail to read the clipboard, and nothing would happen, or, it work fine, but erase your prior clipboard contents (although I tried very hard to save and restore the clipboard. Clipboards under X are slightly…confusing)
Snippits also had some other problems. It was written to solve my problem, and, being somewhat of an advanced Linux user, I didn’t spend too much time on the niceties, like building a package (It was a Ruby gem. Enough said.), or providing even a GUI. The user had to create a keyboard shortcut using a method of their choice (I got a lot of these questions), and then create a set of text files under ~/.snippits to represent their trigger, and expansion. Needless, this is not an absolutely trivial process for the desktop Linux user, the main target user. In my defense, I had a grand road-map to fix all these problems - once I fixed the fundamental flaw described above.
For these and other reasons (like, schoolwork), I slowly lost interest in working on Snippits, and I eventually even stopped using it myself, which was not a good sign, for me and for Snippits. I was forced to go back to typing text manually, and while I kept an eye out for a method to intercept typed text correctly, nothing really turned up. I haven’t touched Snippits for almost a year. Desktop Linux has changed a bit since then.
Today, I came across a project called AutoKey, written by Chris Dekter. It seems to be capable of doing everything Snippits can (except for embedding Ruby in expansions, since it’s written in Python instead), and more besides. It comes with a GUI, a persistent daemon (expansion time is reduced when you don’t have to spin up an entire interpreter, and the program, every time), and some other neat features I wish I had thought of (like the case-matching). It implements the interception of typed text correctly by hooking into X. I haven’t been expanding any text for a long time now, so finding AutoKey was really a boon for me. I’ll be rewriting all my old Snippits expansions immediately.
Snippits wasn’t going anywhere anyway, and AutoKey’s existence is the final nail in the coffin - but it’s a coffin I’m glad to bury. Consider Snippits officially discontinued.1
Maintaining a flawed-by-design program is no fun, and since AutoKey does all I want, I’m set. Perhaps I will learn a bit of Python and contribute some patches myself. I’ve definitely been impressed by AutoKey enough to send a nice donation to Chris. Try AutoKey yourself (especially if you use or used Snippits) and perhaps drop him a bit of cash yourself.
-
Of course, Snippits is licensed under the GPL, and hosted on GitHub, so it’ll be around forever2, so you’re free to fork it and do whatever you want with the code. ↩
-
Yes, forever ↩
