11/11/2005

Using relative directories from shell

I'm a stickler for using exactly the same code in production and development environments. One nice solution to this problem, even though it's not officially 100% possible to do in Unix, is to use directories relative to your executable for all config/support/data files.

I say officially, because in theory a program can be started in such a way that it's mistaken about where it lives. But it's only in really rare cases, done on purpose, that this comes up in practice.

Anyway, in Perl there's nice little module called FindBin that lets you do this easily. But I've never known how to do it nicely in shell.

Well, this bit of ksh seems to work in every case I've tried:

Bin=$(d=$(dirname $0);print $d | grep '^/' || print $(pwd)/$d)

Pretty cool, eh? I'd always thought that if you run something from your $PATH variable, $0 would only have the name relative to whatever it matched in your path. But it turns out modern shells are much nicer about it than that, and always pass the full path from / in this case.

11/04/2005

rikaichan

I just got time to look at rikaichan,

which is a version of the rikaixul plugin for firefox, with many improvements by some fellow named Jon Zarate. I'm very impressed.

The guy didn't make a proper installation link, but one can install it (on windows) by saving the .xpi file to your desktop, opening the file with mozilla, then restarting.

One I get a chance to examine the code I'll probably borrow it back as the next version of rikaixul, but based on first impressions, there are many improvements:
1 - much faster load-time and more efficient afterwards
2 - it stays on for a tab, even when following links
3 - better single-kanji lookup with the shift-key
4 - effectively works as a dictionary as well

Problems:
1 - he doesn't mention the license, which had better be GPL. Since he did the work to make a nice about-box, etc. and made a homepage, it should be made very clear.