Saturday, February 14, 2009

xmsg

Made a handy little script I wanted to share.

I call it xmsg:


#!/bin/bash
"$@" | xmessage -file -


Now, you can put xmsg before any program whose console output you want, and it'll show up in a (albeit archaic looking) dialog box. This is useful when you want to know the console output of something just with the Alt-F2 run dialog, and you don't want to bother opening an actual console.

Put it on the PATH so you don't have to put the whole path to the script, you can just type "xmsg" followed by your command into the Alt-F2 menu (or a console if you want). Quick example:


xmsg df -h


Will give you a nice popup telling you how much space you have on each mount. Now wasn't that more convenient than having to open a console?

How it works (in case a little education can come of this).

"$@" represents all arguments to the script after the name of the script itself. So, this just runs the command you put after xmsg. This pipes to xmessage. xmessage generally makes a dialog with whatever you give it as an argument, but if you say "-file" it will read from a file. If you give "-" as the file, it will read from standard in, which in this case is the output of "$@".

The quotes, btw, on "$@", are because of Bash's annoying quoting rules. Not using them will, I am told, cause arguments with spaces to retokenize.

4 comments:

FreeLikeGNU said...

Just the sort of j00ky I need! thanks!

Francisco

Unknown said...

nice, i like it. although it's sorta concise, a 300 character python one-liner would have been more impressive.

jbalint said...

why not make it a shell alias

Dan said...

I wasn't sure if a shell alias could work that way. Plus, would a shell alias work with the alt-f2 dialog?