Use sed in place of tail -r / tac

Neither tail -r nor tac were portable (although they *should* be), so
instead we'll use sed to accomplish the same thing, reliably.

Testing if dir was a path is actually not desirable, as some wanted
paths are transient, e.g. "bin".

Also indentation fixes.