Feature Request - Provide more UNIX-like view of files/directories
See original GitHub issueTLDR; 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:
- Created 4 years ago
- Reactions:10
- Comments:6 (1 by maintainers)
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 tols
a lot for something that seems like it should be supported directly by PS.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.