Code Monkey home page Code Monkey logo

Comments (10)

vors avatar vors commented on July 22, 2024

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

from zlocation.

rkeithhill avatar rkeithhill commented on July 22, 2024

I'll take a look at it tonight.

from zlocation.

cspotcode avatar cspotcode commented on July 22, 2024

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.

from zlocation.

rkeithhill avatar rkeithhill commented on July 22, 2024

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. :-(

from zlocation.

cspotcode avatar cspotcode commented on July 22, 2024

from zlocation.

rkeithhill avatar rkeithhill commented on July 22, 2024

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.

from zlocation.

cspotcode avatar cspotcode commented on July 22, 2024

from zlocation.

vors avatar vors commented on July 22, 2024

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

from zlocation.

rkeithhill avatar rkeithhill commented on July 22, 2024

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.

from zlocation.

rkeithhill avatar rkeithhill commented on July 22, 2024

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.

from zlocation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.