Jaykul / PowerLine

A more PowerShell prompt
MIT License
567 stars 31 forks source link

Question regarding setup #10

Closed mhartington closed 7 years ago

mhartington commented 7 years ago

Hi there!

I just installed and have been going over the readme and had a question.

Currently on my mac/linux machines, I have my powerline prompt setup to this.

screen shot 2017-01-04 at 1 30 40 pm

Where instead of just printing out the PWD, it prints the whole path from $HOME. But if the path is more than 3 directories deep, it shortens is with the ....

Would such a setup be possible?

Jaykul commented 7 years ago

Hey @mhartington sorry I didn't reply sooner (I really need to shorten the list of projects I get emails about to just mine, so I don't miss issues).

Yes, you can do that, but I hadn't built a slick function for it yet:

function Get-SegmentedPath { 
param($Length = 3)
    $dir = $pwd.Path;
    $buffer = @()
    while($dir) {
        $buffer += @{ Object = (Split-Path $dir -Leaf) }
        $dir = Split-Path $dir
        if(!($Length -= 1)) {
            $buffer += @{ Object = "…"; }
            break
        }
    }
    [Array]::Reverse($buffer)
    $buffer
}

You need to define that, and add a call to that function into your PowerLinePrompt. I'd paste a screenshot, but I don't have a PowerLine font on this PC, so same-color separators look dumb 😊

I'm going to leave this open until I integrate that function to the module

Jaykul commented 7 years ago

Ok, I wrote a much better version of this in /Source/Public/Get-SegmentedPath.ps1

Thraka commented 6 years ago

@Jaykul I'm having a hard time figuring out how to customize the > that gets placed with Get-SegmentedPath when it is in the $prompt variable. Is a setting somewhere?

Jaykul commented 6 years ago

@Thraka yes (you should have opened a new issue to ask this, though).

Yes, there is a ColorSeparator and a Separator (and reverse versions of each for right-aligned blocks). You can set them in a hashtable which currently lives as a static property. Type this to see the list, then set the one you want:

[PoshCode.Pansies.Entities]::ExtendedCharacters

That hashtable (and the one in [PoshCode.Pansies.Entities]::EscapeSequences) are saved when you Export-PowerLinePrompt and will be reloaded automatically when the module imports.

Thraka commented 6 years ago

@Jaykul I know sorry i broke issue etiquette.. sorry :(

I think I found my fix. The problem is that ExtendedChars are characters, not strings. And the delimiter used throughout the scripts (the fancy >) burdens my eyes when they jam up close to other text, like in the directory path.

Playing around and learning how this all works, which has been hours of fun, (really it has, this is cool stuff) I figured out how to get what I want. In the $prompt array I'm adding spaces around the separator character to override segmentedpath's default.

{ New-PromptText { (Get-SegmentedPath -SegmentLimit 7) -join (" $([PoshCode.Pansies.Entities]::ExtendedCharacters["Separator"]) ") } -BackgroundColor DarkBlue -ForegroundColor White },
Jaykul commented 6 years ago

Well, all things considered ... I have no problem with the idea of getting rid of the character entities and making everything strings. Not a bad idea, really.