Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path info in default z output is clipped #60

Closed
rkeithhill opened this issue Sep 12, 2018 · 10 comments
Closed

Path info in default z output is clipped #60

rkeithhill opened this issue Sep 12, 2018 · 10 comments

Comments

@rkeithhill
Copy link
Contributor

The clipping below is unfortunate:

z

Name                           Value
----                           -----
C:\Users\Keith                 49
C:\Users\Keith\GitHub          2
C:\Users\Keith\GitHub\dahlb... 6
C:\Windows\System32            13
C:\Users\Keith\Code\electro... 16
C:\Users\Keith\Code\electro... 26

Maybe you could just switch the default order Name and Value e.g.:

z | ft Value,Name

Value Name
----- ----
   52 C:\Users\Keith
    2 C:\Users\Keith\GitHub
    6 C:\Users\Keith\GitHub\dahlbyk\posh-git
   13 C:\Windows\System32
   16 C:\Users\Keith\Code\electron-app\dist
   26 C:\Users\Keith\Code\electron-app
@vors
Copy link
Owner

vors commented Sep 13, 2018

Totally! Would you like to send a PR? :)

@rkeithhill
Copy link
Contributor Author

I'll take a look at it tonight.

@cspotcode
Copy link
Contributor

I think you'll have to set a defaultdisplaypropertyset on the returned values.

https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.typedata.defaultdisplaypropertyset?view=powershellsdk-1.1.0

It might be tricky because it's technically a single Hashtable value being returned, which I think is being enumerated as a bunch of DictionaryEntrys. So they're controlling the rendering. You might need to replace the returned value with some sort of custom collection.

@rkeithhill
Copy link
Contributor Author

Yup, I was initially trying to stick with the hashtable and give the "DictionaryEntry" objects a new type name in their typenames collection. But GetEnumerator() generates new DictionaryEntry objects. :-(

@cspotcode
Copy link
Contributor

cspotcode commented Sep 19, 2018 via email

@rkeithhill
Copy link
Contributor Author

Class syntax would limit this module to v5 and higher. I don't think that is ideal but it's up to @vors. Maybe we could return a PSCustomObject but maintain a module level, private variable that is the hashtable for quick lookup of the weight from the path (key). Also, to work better on Linux the hashtable/dictionary should be case-sensitive.

@cspotcode
Copy link
Contributor

cspotcode commented Sep 20, 2018 via email

@vors
Copy link
Owner

vors commented Sep 20, 2018

I opened #64 for the 5.0 question, I'm a little bit on the fence about it.
I think this works ( 🤷‍♀️ ):

... .GetEnumerator() | Select-Object -Property Name, Value

@rkeithhill
Copy link
Contributor Author

rkeithhill commented Sep 21, 2018

If we only intend to change the behavior of Invoke-Location (and z - alias to this function) that should work. Although it would need to be something like this:

    if ($null -eq $match) {
        Get-ZLocation |
            ForEach-Object GetEnumerator |
            Select-Object @{Name='Weight';Expression={$_.Value}},@{Name='Path';Expression={$_.Name}}
        return
    }

Outputs:

Weight Path
------ ----
     3 C:\Users\Keith\GitHub\rkeithhill\ZLocation
     1 C:\Users\Keith
     6 C:\Users\Keith\GitHub\rkeithhill\ZLocation\ZLocation

Although that outputs a series of DictionaryEntry objects with Weight/Path properties tacked on. That feels a bit odd. The output of Invoke-Location is not internally used so we could probably get away with changing the output from hashtable to something else. I think a set of PSCustomObjects would probably be better. External users can still access the hashtable by calling Get-ZLocation. Thoughts? If you agree in principle I submit a PR for this.

@rkeithhill
Copy link
Contributor Author

OK, this is the [PSCustomObject] version:

    if ($null -eq $match) {
        Get-ZLocation |
            ForEach-Object {$_.GetEnumerator()} |
            ForEach-Object {[PSCustomObject]@{Weight = $_.Value; Path = $_.Name}}
        return
    }

Now, need to figure out how far back [PSCustomObject] goes. I think it goes back to v3. If so, we'd be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants