Nushell: auto sort-by name for ls on macOS

Created on 28 Sep 2019  ยท  5Comments  ยท  Source: nushell/nushell

Version: 0.3.0
Installed via Cargo

On my Windows machine, it seems that ls sorts the results by name automatically (not sure if this is a function of ls or autoview). I was also expecting this same behavior on my macOS machine, but it turns out that's not the case.

Is this an error on my end? Is this expected? Is there a way to configure this?

/Users/zooce/Developer> ls
โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
 #  โ”‚ name                                   โ”‚ type      โ”‚ readonly โ”‚ size   โ”‚ created      โ”‚ accessed     โ”‚ modified
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  0 โ”‚ OpenPixelProject                       โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 4 months ago โ”‚ 3 weeks ago  โ”‚ 4 months ago
  1 โ”‚ .DS_Store                              โ”‚ File      โ”‚          โ”‚ 8.2 KB โ”‚ 4 years ago  โ”‚ a day ago    โ”‚ 3 months ago
  2 โ”‚ SDKs                                   โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 5 months ago โ”‚ 3 weeks ago  โ”‚ 5 months ago
  3 โ”‚ libLCS-0.0.59.zip                      โ”‚ File      โ”‚          โ”‚ 1.3 MB โ”‚ 4 months ago โ”‚ 4 months ago โ”‚ 4 months ago
  4 โ”‚ other                                  โ”‚ Directory โ”‚          โ”‚ 544 B  โ”‚ 4 years ago  โ”‚ 3 weeks ago  โ”‚ 4 months ago
  5 โ”‚ logisim-macosx-2.7.1.tar.gz            โ”‚ File      โ”‚          โ”‚ 6.4 MB โ”‚ 4 months ago โ”‚ 4 months ago โ”‚ 4 months ago
  6 โ”‚ Logisim.app                            โ”‚ Directory โ”‚          โ”‚ 128 B  โ”‚ 9 years ago  โ”‚ 3 weeks ago  โ”‚ 9 years ago
  7 โ”‚ OMSCS                                  โ”‚ Directory โ”‚          โ”‚ 512 B  โ”‚ 2 years ago  โ”‚ a day ago    โ”‚ 2 weeks ago
  8 โ”‚ zooce.itermcolors                      โ”‚ File      โ”‚          โ”‚ 8.4 KB โ”‚ 7 months ago โ”‚ 7 months ago โ”‚ 7 months ago
  9 โ”‚ Github                                 โ”‚ Directory โ”‚          โ”‚ 1.8 KB โ”‚ 4 years ago  โ”‚ 3 weeks ago  โ”‚ 3 weeks ago
 10 โ”‚ ML                                     โ”‚ Directory โ”‚          โ”‚ 992 B  โ”‚ a year ago   โ”‚ a week ago   โ”‚ a year ago
 11 โ”‚ mbadolato-iTerm2-Color-Schemes-b349774 โ”‚ Directory โ”‚          โ”‚ 608 B  โ”‚ 8 months ago โ”‚ 3 weeks ago  โ”‚ 8 months ago
 12 โ”‚ externlibs                             โ”‚ Directory โ”‚          โ”‚  96 B  โ”‚ 3 months ago โ”‚ 3 weeks ago  โ”‚ 3 months ago
 13 โ”‚ rust_by_example                        โ”‚ Directory โ”‚          โ”‚  96 B  โ”‚ 3 months ago โ”‚ 3 weeks ago  โ”‚ 3 months ago
 14 โ”‚ Fonts                                  โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 3 years ago  โ”‚ 3 weeks ago  โ”‚ 3 years ago
 15 โ”‚ Godot                                  โ”‚ Directory โ”‚          โ”‚ 128 B  โ”‚ 4 months ago โ”‚ 3 weeks ago  โ”‚ 4 months ago
โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
/Users/zooce/Developer> ls | sort-by name
โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฏโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
 #  โ”‚ name                                   โ”‚ type      โ”‚ readonly โ”‚ size   โ”‚ created      โ”‚ accessed     โ”‚ modified
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  0 โ”‚ .DS_Store                              โ”‚ File      โ”‚          โ”‚ 8.2 KB โ”‚ 4 years ago  โ”‚ a day ago    โ”‚ 3 months ago
  1 โ”‚ Fonts                                  โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 3 years ago  โ”‚ 3 weeks ago  โ”‚ 3 years ago
  2 โ”‚ Github                                 โ”‚ Directory โ”‚          โ”‚ 1.8 KB โ”‚ 4 years ago  โ”‚ 3 weeks ago  โ”‚ 3 weeks ago
  3 โ”‚ Godot                                  โ”‚ Directory โ”‚          โ”‚ 128 B  โ”‚ 4 months ago โ”‚ 3 weeks ago  โ”‚ 4 months ago
  4 โ”‚ Logisim.app                            โ”‚ Directory โ”‚          โ”‚ 128 B  โ”‚ 9 years ago  โ”‚ 3 weeks ago  โ”‚ 9 years ago
  5 โ”‚ ML                                     โ”‚ Directory โ”‚          โ”‚ 992 B  โ”‚ a year ago   โ”‚ a week ago   โ”‚ a year ago
  6 โ”‚ OMSCS                                  โ”‚ Directory โ”‚          โ”‚ 512 B  โ”‚ 2 years ago  โ”‚ a day ago    โ”‚ 2 weeks ago
  7 โ”‚ OpenPixelProject                       โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 4 months ago โ”‚ 3 weeks ago  โ”‚ 4 months ago
  8 โ”‚ SDKs                                   โ”‚ Directory โ”‚          โ”‚ 160 B  โ”‚ 5 months ago โ”‚ 3 weeks ago  โ”‚ 5 months ago
  9 โ”‚ externlibs                             โ”‚ Directory โ”‚          โ”‚  96 B  โ”‚ 3 months ago โ”‚ 3 weeks ago  โ”‚ 3 months ago
 10 โ”‚ libLCS-0.0.59.zip                      โ”‚ File      โ”‚          โ”‚ 1.3 MB โ”‚ 4 months ago โ”‚ 4 months ago โ”‚ 4 months ago
 11 โ”‚ logisim-macosx-2.7.1.tar.gz            โ”‚ File      โ”‚          โ”‚ 6.4 MB โ”‚ 4 months ago โ”‚ 4 months ago โ”‚ 4 months ago
 12 โ”‚ mbadolato-iTerm2-Color-Schemes-b349774 โ”‚ Directory โ”‚          โ”‚ 608 B  โ”‚ 8 months ago โ”‚ 3 weeks ago  โ”‚ 8 months ago
 13 โ”‚ other                                  โ”‚ Directory โ”‚          โ”‚ 544 B  โ”‚ 4 years ago  โ”‚ 3 weeks ago  โ”‚ 4 months ago
 14 โ”‚ rust_by_example                        โ”‚ Directory โ”‚          โ”‚  96 B  โ”‚ 3 months ago โ”‚ 3 weeks ago  โ”‚ 3 months ago
 15 โ”‚ zooce.itermcolors                      โ”‚ File      โ”‚          โ”‚ 8.4 KB โ”‚ 7 months ago โ”‚ 7 months ago โ”‚ 7 months ago
โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ทโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
enhancement investigate question

All 5 comments

900

The files are unordered on Linux as well. I switched to lsd because of this.

This was fixed in #1192.

It's being removed in https://github.com/nushell/nushell/pull/1286. I like this PR because it unifies two codepaths. Previously, a glob pattern wouldn't result in sorted results, meaning the behaviour was already inconsistent, so I don't feel like we're losing anything by dropping that code for now.

I wonder if we could have some configuration that would result in expanding ls differently when it's at the end of the pipeline. For example, ls would expand into ls | sort-by name | autoview. We could also have ls consume that configuration. Thoughts?

Regardless, sorting can be expensive and unnecessary in a lot of cases, so I'd rather it be opt-in via configuration/flag than opt-in by default. That's my five cents ๐Ÿ™‚

I totally agree that defaulting to the sorted case is probably not the best idea.

+1 for allowing this to be configurable -- this way I don't have to add a flag or pipe it to sort-by every time

(either way, nu_shell is dope -- to all contributors, keep up the great work!)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathandturner picture jonathandturner  ยท  6Comments

llimllib picture llimllib  ยท  5Comments

cdhunt picture cdhunt  ยท  5Comments

coolshaurya picture coolshaurya  ยท  4Comments

senden9 picture senden9  ยท  3Comments