Revamp `ls` handling

Refactor handling of `ls` to be clean and consistent across different
platforms and options.