Clean up and reduce memory allocations in string escaping
Enhance/fix `isatty` to actually handle specifed file descriptors.

  Presently, `isatty` only works on a handful of keywords, and
  uses redirection shorthand (i.e., 0>&2). It is pretty prickly if
  one doesn't give it an argument that it likes. This change would
  allow the handling of any normal file path as well, which is how
  to my intuition at least, a function called _isatty_ should work.

  Note that there a bug in fish's built-in `test`, and in order to
  retain bug-compatible functionality, this is a bit lengthier than
  it aught to be. See the comments in the commit or issue #1228.