Perhaps one of my favorite features or tools with the Mac OS X operating system is the ability to use text-expanding programs such as Typinator or TextExpander. These programs allow you to type a keyword, regardless of the focused application, and have it expand into a custom string, set of text, or image. These text-expanding tools are a constantly-used time saver.

On Linux, there is nothing as comprehensive as Typinator or TextExpander on the Mac. There is one program that comes close, but is not as fluid or elegant as the Mac equivalents.

The program is called Snippits, and it also expands text based on predefined keywords. Snippits is a Ruby program and requires a little bit of effort to install, depending on the Linux distribution in use.

On Debian and Ubuntu it is easier to install because one of the prerequisite packages, xautomation, is readily available. On Mandriva Linux, the package is not available and so must be compiled from source, which is easy enough to accomplish.

With any distribution, at the very least you will need to install aspell and its development files; Ruby and its development files; and also whichever package provides Ruby’s gem support. On a Debian system, this can be accomplished by executing:

# apt-get install ruby ruby1.8-dev rdoc rubygems libruby-extras xautomation xsel aspell libaspell-dev aspell-en build-essential

On Mandriva Linux, because xautomation must be compiled from source, the following is required. Note the commands on a # prompt are executed as root, whereas those with a $ prompt should be executed as a regular user. As a result, the below is somewhat abbreviated; you may elect to use sudo (if you have configured it appropriately) or su to the root user when required.

# urpmi ruby-RubyGems ruby-devel aspell-devel aspell-en x11-devel png-devel
$ curl -O -L
$ tar xvzf xautomation-1.02.tar.gz
$ cd xautomation-1.02
$ ./configure && make
# make install

Once this is done, the Snippits gem must be installed and Ruby configured to use Rubygems by modifying the ~/.bashrc startup file:

$ echo 'export RUBYOPT="rubygems"' >>~/.bashrc && source ~/.bashrc
# gem install raspell
# gem install snippits

This will install the RASpell gem which is required by the Snippits gem, and then compile and install the Snippits gem.

Once this is completed, you can test Snippits. Snippits are stored in the ~/.snippits/ directory; each file is its own snippit. For instance:

$ mkdir ~/.snippits
$ echo "this is a snippit test" >~/.snippits/test
$ snippit test
this is a snippit test
$ ks test
this is a snippit test
$ this is a snippit test

The snippit [name] command outputs the contents of the file named [name]; in this case ~/.snippits/test. Using the ks command, the contents are not only outputted, but are also used as input for the next command.

Snippits allows for a lot of extra modifiers to really manipulate text, such as {enter} to type an enter keystroke or {tab} to enter a tab keystroke. For instance, if a snippit were defined in ~/.snippits/pstest as:

ps aux|grep {cursor}|wc -l

Executing ks pstest would result in the above being printed on the command-line with the cursor being positioned where the {cursor} string is located, exactly where you would want the cursor to be to type what to grep for.

The above has only illustrated Snippits’ use for command-line usage. It is possible to bind the ks command to a global hotkey in KDE or GNOME which would allow for Snippits to be used in any application. The drawback here, compared to the Mac-equivalent programs, is the need for the hotkey to begin with as there doesn’t seem to be a way to make Snippit automatically transform text based on the appearance of the keyword — perhaps in a future version. The application is under active development and definitely looks to have promise.

Get the PDF version of this tip here.

Delivered each Tuesday, TechRepublic’s free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!