You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modern alternatives to ls such as lsd or exa usually display additional helpful contextual information allowing the user to understand at a glace what each file is and its status. This includes an icon that illustrates the file's mime type (for instance, an icon of a picture for image files) and/or a letter or symbol representing the file's git status (for instance, "M" for a file that has been modified since the last commit). Providing this information in the default ls command would make it generally more versatile for users and provide much more flexibility in scripting. For instance, a user could make a script iterating over untracked files of a git repo, or a script that only executes on image/* files.
Describe the solution you'd like
Allowing the type column in ls to display the mime type of a file, with an optional flag to return to the "legacy" option of simply displaying "file".
Adding a git status column displayed when the directory is in a git repository indicating the file's git status.
Describe alternatives you've considered
No response
Additional context and details
I am already working on a simple fork implementing these features on Linux as it's a feature I wanted on my own personal version, though I believe it could be interesting for it to be implemented upstream.
So the thing about Nushell ls is that, because of how it's meant to be filtered through select name and such instead of just displayed, the default setting is designed to perform the minimum of filesystem I/O. This is why -d and --all aren't the default. So, things like this type column would better belong behind a flag.
By the way, is there even an easy way to compute the MIME type of arbitrary files? I know that the file POSIX command uses a database called /usr/share/file/magic, but that just outputs an arbitrary and non-uniform description.
new_mime_guess is what I was going for too, it works well and doesn't seem too demanding. Plus, similarly to how exa does it, information like git status that could take longer to identify should be disabled by default.
It could be useful for tasks applied to an entire type of files without having to parse the file extension manually. For instance, a user could display all images in a directory, regardless of if they are a png, jpg, or anything else, by just doing ls -t | where type =~ image (with -t being the flag to show mime type). It would in general help the user automate tasks intuitively.
For a personal case, I have had some of my scripts break when dealing with rather recent image formats like avif and webp just because of the fact I manually handled extensions. By supporting mime-types, we are providing a helpful option for flexibility and categorization.
I actually do like the idea of making this more fundamental to nushell rather than an ls specific thing, though that sounds like quite the undertaking.
That's pretty much exactly how I prototyped it as well in my fork, this also seems to work on Windows from my testing, though I haven't had the time to write proper tests yet.
How about instead of putting it in the "type" column, a new "mime" column is added to ls when -m is used? I think having one column suddenly change meaning off of a flag is a bit unseemly.
I would strongly suggest, as already hinted in the discussion I initiated, that this example is nice, but "type" should be "mime" in this case.
The reason for that is, that "type" is extremely generic. It could be anything. For example, it could be some internal Nu-specific type or something. When it's called "mime", there is no debate. It's short, quick & correct, without ambiguity.
I have read your reasoning & deem it valid. I think, both of us have a point & I can see either option making sense.
I personally don't like mixing up stuff like column definitions, which is kind of anti-functional, but on the other hand it might get confusing to add more & more different column names to remember over time.
Additional argument for future "standard library/core" consideration. git although a de facto standard by virtue of being predominantly used, is just one of several implementations of a version control system. hg / svn etc. still exist. Introducing it to the core would thus be a well intentioned opinionated decision but not foster a standard or increase interoperability.
Things that make nushell use work better across Windows and Unixes or implement the core of a common standard on the other hand reinforce efforts to make things standardized and seamlessly cross-platform.
kind of unrelated but I wonder if it's possible for someone to write a plugin that replaces and internal command. for instance, i wonder if someone wrapped the exa or lsd code in a nushell plugin and named it ls, would that work? i have no idea but it's interesting.
Activity
fdncred commentedon Dec 27, 2022
Would you mind including some screenshots? I think this sounds cool and would like to see what it looks like. Thanks!
We do have icons like this, that were borrowed from
exanushell/crates/nu-command/src/viewers/icons.rs
Line 6 in 38fc42d
webbedspace commentedon Dec 27, 2022
So the thing about Nushell
lsis that, because of how it's meant to be filtered throughselect nameand such instead of just displayed, the default setting is designed to perform the minimum of filesystem I/O. This is why-dand--allaren't the default. So, things like thistypecolumn would better belong behind a flag.By the way, is there even an easy way to compute the MIME type of arbitrary files? I know that the
filePOSIX command uses a database called/usr/share/file/magic, but that just outputs an arbitrary and non-uniform description.fdncred commentedon Dec 27, 2022
For mime-type, I'm guessing we'd just infer the type by the extension. Anything else would probably be to impactful. Maybe something like this https://github.com/Lynnesbian/new_mime_guess ?
KodiCraft commentedon Dec 27, 2022
new_mime_guessis what I was going for too, it works well and doesn't seem too demanding. Plus, similarly to howexadoes it, information like git status that could take longer to identify should be disabled by default.fdncred commentedon Dec 27, 2022
I don't see the benefit of mime-type. Why do we need that? What's a use-case for it?
KodiCraft commentedon Dec 27, 2022
It could be useful for tasks applied to an entire type of files without having to parse the file extension manually. For instance, a user could display all images in a directory, regardless of if they are a png, jpg, or anything else, by just doing
ls -t | where type =~ image(with -t being the flag to show mime type). It would in general help the user automate tasks intuitively.For a personal case, I have had some of my scripts break when dealing with rather recent image formats like
avifandwebpjust because of the fact I manually handled extensions. By supporting mime-types, we are providing a helpful option for flexibility and categorization.theAkito commentedon Dec 27, 2022
Basically, more or less roughly, what I have been suggesting here.
#7524
KodiCraft commentedon Dec 27, 2022
I actually do like the idea of making this more fundamental to nushell rather than an
lsspecific thing, though that sounds like quite the undertaking.fdncred commentedon Dec 27, 2022
Thoughts?

I'm basically saying, "if it's a file, show me the mime type, if -m is used".
KodiCraft commentedon Dec 27, 2022
That's pretty much exactly how I prototyped it as well in my fork, this also seems to work on Windows from my testing, though I haven't had the time to write proper tests yet.
webbedspace commentedon Dec 27, 2022
How about instead of putting it in the "type" column, a new "mime" column is added to
lswhen-mis used? I think having one column suddenly change meaning off of a flag is a bit unseemly.KodiCraft commentedon Dec 27, 2022
To be fair, that already somewhat happens with -d, the flag makes the 'type' column more specific in the same way -d does the 'size' column.
theAkito commentedon Dec 27, 2022
I would strongly suggest, as already hinted in the discussion I initiated, that this example is nice, but "type" should be "mime" in this case.
The reason for that is, that "type" is extremely generic. It could be anything. For example, it could be some internal Nu-specific type or something. When it's called "mime", there is no debate. It's short, quick & correct, without ambiguity.
fdncred commentedon Dec 27, 2022
I stated my case in #7616 on
typevsmime.theAkito commentedon Dec 27, 2022
I have read your reasoning & deem it valid. I think, both of us have a point & I can see either option making sense.
I personally don't like mixing up stuff like column definitions, which is kind of anti-functional, but on the other hand it might get confusing to add more & more different column names to remember over time.
Both ways are reasonable.
add `--mime-type(-m)` to `ls` in the `type` column (#7616)
KodiCraft commentedon Dec 27, 2022
PR implementing the git status feature: #7620
sholderbach commentedon Dec 28, 2022
I think based on the fact that #7616 landed with mime-types (in scope as it is a common system interface) and the discussion on #7620 concluded that tight coupling with git is outside of the scope of the core nushell project we should close this issue and encourage plugins or scripts contributing further git integrations through https://github.com/nushell/nu_scripts or https://github.com/nushell/awesome-nu
Additional argument for future "standard library/core" consideration. git although a de facto standard by virtue of being predominantly used, is just one of several implementations of a version control system.
hg/svnetc. still exist. Introducing it to the core would thus be a well intentioned opinionated decision but not foster a standard or increase interoperability.Things that make nushell use work better across Windows and Unixes or implement the core of a common standard on the other hand reinforce efforts to make things standardized and seamlessly cross-platform.
KodiCraft commentedon Dec 28, 2022
Closed, see above comment
fdncred commentedon Dec 28, 2022
kind of unrelated but I wonder if it's possible for someone to write a plugin that replaces and internal command. for instance, i wonder if someone wrapped the exa or lsd code in a nushell plugin and named it
ls, would that work? i have no idea but it's interesting.webbedspace commentedon Dec 28, 2022
You can already write aliases over internals, can't you?
alias ls = ls -aworks (though I wouldn't use it).fdncred commentedon Dec 28, 2022
Yes, you can do that wish aliases and custom commands. I assume the same would work with plugins but I'm not sure as I've never done it.
hkalbasi commentedon Aug 15, 2026
I wanted to use
ls -minstead offileto improve speed of my nushell script. Why it doesn't read the file content?