Fix infinite recursion bug
Simplified prompt code.

Also limits pwd output length according to available space.

Found this code on a server, it seems to work :)