Open Source

Expanding text with Snippits in Linux

Vincent Danen admires the Mac text-expanding tools like Typinator or TextExpander and has been looking for a similar tool in Linux. The best counterpart he found is a program called Snippits. Here are the basics.

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 http://hoopajoo.net/static/projects/xautomation-1.02.tar.gz
$ 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!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

4 comments
Alganon
Alganon

If I understand the idea correctly, this is also a feature of the Palm OS. In my LifeDrive, I have a feature called "Shortcuts". An upstroke on the Graffiti pad alerts the device to an incoming shortcut, which may consist of 2 or more characters (preferably letters). For example: Upstroke followed by "esd" generates a string "1 x 25L Eco-System Dish Machine detergent". I had a number of other products stored in my shortcuts and placing an order by SMS was a breeze, and it revolutionised the ordering process for that company. The limitation was the 254 character limit of the SMS service. But the expanded text could be used anywhere; in emails, quotations created in the Word Processor, memos or tasks, even calendar. This could be great for a sig, any where it was needed. Andrew Greig

Photogenic Memory
Photogenic Memory

This is silly but it's fun. Check'em out: ]$ ./figlet -f digital Master Yoda! +-+-+-+-+-+-+ +-+-+-+-+-+ |M|a|s|t|e|r| |Y|o|d|a|!| +-+-+-+-+-+-+ +-+-+-+-+-+ ]$ ./figlet -f bubble.flf I broke my sword?! _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ ( I ) ( b | r | o | k | e ) ( m | y ) ( s | w | o | r | d | ? | ! ) \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ ]$ ./figlet -f slant.flf figlets ROCK! _____ __ __ ____ ____ ________ __ __ / __(_)___ _/ /__ / /______ / __ \/ __ \/ ____/ //_// / / /_/ / __ `/ / _ \/ __/ ___/ / /_/ / / / / / / ,< / / / __/ / /_/ / / __/ /_(__ ) / _, _/ /_/ / /___/ /| |/_/ /_/ /_/\__, /_/\___/\__/____/ /_/ |_|\____/\____/_/ |_(_) /____/ I guess it doesn't work for everything when you paste it into a text( above ) forms but its fun to use and waste some time.

criddel74
criddel74

Will this work in UNIX or is there a UNIX equivalent?

vdanen
vdanen

If you have the pre-requisite software installed (ruby, etc.) then I don't see why it wouldn't.

Editor's Picks