Avatar
Linux, plaintext & minimalism
October 13, 2018

Grouping and sorting regular and symlinked folders before files with ls in zsh

By default ls sorts all folders, symlinked folders and files by name and not by type and then by name, which is very annoying and sometimes even confusing.

Thankfully you can change this behavior pretty easy, you just need to add one small function to your zsh configuration:

dir1st() { [[ -d $REPLY ]] && REPLY=1-$REPLY || REPLY=2-$REPLY;}

Then call it like this:

ls -ldU -- *(o+dir1st)

And here’s an example image:

If you’re a Bash user and knows how to make this work there, let me know! I’m pretty sure there’s a lot of Bash users out there who would want this as well.

Tags: zsh

Feedback

I don't have a commenting system simply because I haven't found a solution that I like. If you want to leave any feedback and/or have any questions, feel free to contact me either via e-mail, fediverse, XMPP or IRC (I'm Hund at freenode.net).