Instead of hacking around and parsing ls
output—which is never a good idea—you could simply install the GNU Coreutils, which give you the GNU versions of ls
, date
, echo
, head
and tail
, and many more, which offer much more than the BSD counterparts.
The easiest way to do that would be to install Homebrew, and then run brew install coreutils
. Now, the GNU coreutils will be available prefixed with a g
, and you could run:
gls -l --group-directories-first
Or, you could even alias that in your .zshrc
:
alias ls='gls --group-directories-first'
ls
on Mac. github.com/torstenvl/betterls