n8blog
distraction in action

Like my work? Check out HexaLex, my game for iPhone & iPod Touch. It's a crossword game like Scrabble, but played with hexagonal tiles. http://www.hexalex.com

Posts in category Utilities :

This is a little script that calculates the shortest relative path from a directory to one or more arbitrary paths. For example:

[n8gray@golux photos]$ pwd
/Users/n8gray/web/Sites/photos
[n8gray@golux photos]$ relpath . ~/Pictures/
../../Pictures
[n8gray@golux photos]$ relpath /usr/local /usr/local/bin/nedit
./bin/nedit
[n8gray@golux photos]$ relpath / /
./
[n8gray@golux photos]$ relpath . ..
../
[n8gray@golux photos]$ relpath . /usr/local ~/bin ../photos/Cats/index.html
../../../../usr/local
../../bin
./Cats/index.html

Caveat Emptor: Symbolic links are resolved when you give a relative path but not when you give an absolute path. I intend to make this more deterministic and controllable in the future.

Get it here. Python 2.3 required.

  • Share/Bookmark

Like my work? Check out HexaLex, my game for iPhone & iPod Touch. It's a crossword game like Scrabble, but played with hexagonal tiles. http://www.hexalex.com