shell-common: cope better when we can't trim the path sensibly

Previously, you'd see an error about a regex having n be greater than m
if there was no sensible way to trim the path.  Now, we'll simply wrap
around the screen.  Unfortunately, the return code wasn't printing
properly in that case, so that is fixed as well.