question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request - Provide more UNIX-like view of files/directories

See original GitHub issue

TLDR; I’m unhappy with the view for gci on my Mac so I did something about it

Summary of the new feature/enhancement

I’ve been thinking that the Get-ChildItem experience on Linux/Mac is not providing as much information as I would like. We don’t report user, group or a real mode, and size for directories is not reported.

Proposed technical implementation details (optional)

Consider the difference between ls -ld /opt and Get-Item /opt (this is the same for files, but I am attempting to avoid a large amount of output).

PS> /bin/ls -ld /opt
drwxr-xr-x  3 root  wheel  96 Mar 16 14:14 /opt
PS> gi /opt


    Directory: /

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-r--           3/16/2019  2:14 PM                opt

There’s a useful mode description, as well as owner/group info. The LastWriteTime is a bit tidier (imo) and then there’s a length reported for a directory. All that extra info is down to the stat API which provides all this information. Unfortunately, the stat API is way different between platforms; the struct property layout is different, some of the properties are different types (inode can be an int or a long), etc), so it’s a bit of a mess and you can’t just simply wrap stat in c# and be portable.

I spent a little time in constructing a common stat structure which could smooth out the underlying differences between platforms and present useful data which could be used in the filesystem provider and provide a better (to me, anyway) experience.

Here’s what I’ve got so far:

PS> gi /opt | ft -view childrenWithUnixStat


    Directory: /

UnixMode   User       Group       LastWriteTime           Size Name
--------   ----       -----       -------------           ---- ----
drwxr-xr-x root       wheel        Mar 16 02:14             96 opt

It handles the usual pipes, char/block devices

PS> ls /dev/zero


    Directory: /dev

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----           8/14/2019  5:31 PM              0 zero

PS> ls /dev/zero | ft -view childrenWithUnixStat


    Directory: /dev

UnixMode   User       Group       LastWriteTime           Size Name
--------   ----       -----       -------------           ---- ----
crw-rw-rw- root       wheel        Aug 14 05:31              0 zero

My implementation leads to some cool side effects:

PS> gci /dev | group group

Count Name                      Group
----- ----                      -----
    1 _windowserver             {/dev/xcpm}
   43 operator                  {/dev/disk0, /dev/disk0s1, /dev/disk0s2, /dev/disk1…}
    1 staff                     {/dev/console}
   12 tty                       {/dev/ptmx, /dev/ttys000, /dev/ttys001, /dev/ttys002…}
  301 wheel                     {/dev/fd, /dev/afsc_type5, /dev/auditpipe, /dev/auditsessions…}

PS> gci /dev | group unixmode

Count Name                      Group
----- ----                      -----
   17 brw-r-----                {/dev/disk0, /dev/disk0s1, /dev/disk0s2, /dev/disk1…}
    1 cr--r--r--                {/dev/io8logmt}
   17 crw-------                {/dev/afsc_type5, /dev/auditpipe, /dev/autofs, /dev/autofs_control…}
   11 crw--w----                {/dev/ttys000, /dev/ttys001, /dev/ttys002, /dev/ttys003…}
   17 crw-r-----                {/dev/rdisk0, /dev/rdisk0s1, /dev/rdisk0s2, /dev/rdisk1…}
    2 crw-r--r--                {/dev/auditsessions, /dev/fsevents}
    1 crw-rw----                {/dev/xcpm}
  288 crw-rw-rw-                {/dev/autofs_homedirmounter, /dev/autofs_notrigger, /dev/autofs_nowait, /dev/cu.Bluetooth-Incoming-Port…}
    1 dr-xr-xr-x                {/dev/fd}
    3 lr-xr-xr-x                {/dev/stderr, /dev/stdin, /dev/stdout}

PS> gci / | group { $_.UnixStat.HardLinkCount}

Count Name                      Group
----- ----                      -----
    1 3                         {/opt}
    1 5                         {/System}
    1 6                         {/Users}
    1 65                        {/Library}
    1 84                        {/Applications}

I have done the barest of performance analysis, but I’m not seeing much impact.

Implementation wise, I did this in PowerShell-Native where I smoothed out stat to be x-plat and then extended the native calls in CorePsPlatform, and called them from ProviderBase, extended types in Types_Ps1Xml and created a new format in FileSystem_format_ps1xml.

My question to you all: Do you think this has legs? Should I spend more time on it? I’m already personally finding it useful, but not sure whether anyone really cares.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
rkeithhillcommented, Aug 30, 2019

I very much like the idea of surfacing platform-specific and useful information from gci. On Linux, it is currently of limited use. I find I’m falling back to ls a lot for something that seems like it should be supported directly by PS.

0reactions
JoseRa-KnowITcommented, Oct 3, 2019

I very much like this proposal, even me as a windows guy I tend to use the native ls command on wsl or linux, because GCI well… the point was already said, so I can´t even imagine the feeling of a purist brave-heart linux guy trying to give a chance to pwsh.

But I think as @TobiasPSP wisely exposed, all commands should be standard and consistent on every platform, so there must be a kind of in-between solution that benefit users of all platforms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sloth – A Mac app that shows all open files, directories ...
Opening this and then searching for "\.db$" reveals all of the processes that are (probably) using SQLite, which is fun for finding things...
Read more >
CVE-2021-21364 Detail - NVD
When files/directories are created, the default `umask` settings for the process are respected. As a result, by default, most processes/apis ...
Read more >
Why is Linux's filesystem designed as a single directory tree?
Users can work in a subtree of the filesystem and ignore the rest, and still benefit from directories to organize their files. Directories...
Read more >
What is the command to list the contents of a directory in ...
The best way in my opinion is the list command written as ls ls shows the files in a directory ls -l shows...
Read more >
Do advanced Linux disk usage diagnostics with this ...
In this article, I will cover three advanced disk utilization diagnostic topics, including one that leverages a feature I added in version ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found