Closed nebula-it closed 1 year ago
Try Write-Host -NoNewline
Dang, can't believe I didn't think of that. Anyways, thank you for quick answer @dahlbyk :)
Hey @dahlbyk ,
Is there an easy way to get length of $gitStatus
in $gitStatus = & $GitPromptScriptBlock
. I'm looking to add a right hand side prompt as well so need the number of characters that will be printed in my prompt for the calculation. Using $gitStatus.Length
does not yield correct value as there are non-standard chars in there. e.g
> '[master ≡ +1 ~0 -0 | +2 ~1 -0 !]'.Length
32
v/s
>(& $GitPromptScriptBlock).length
154
I've gotten close by using some regex
>$1gitStatus = & $GitPromptScriptBlock
>([regex]::Matches($1gitStatus, "[[:print:]]*" )).Count
27
But it still misses few characters, even hardcoding those doesnt work well.
> ([regex]::Matches($1gitStatus, "[[:print:]]*|[≡↑↓↕×|+~-]" )).count
35
So, before I dig deep into this rabbit hole, just wanted to check with you if there is an easier way to get the number printed chars from $GitPromptScriptBlock
Cheers
Managed to get it using $gitStatusLength = ($gitStatus -replace '\x1b\[[0-9;]*[a-z]', '').Length
System Details
Issue Description
I'm trying to use posh-git with a custom prompt. I have custom prompt logic already setup, plus it writes some of the stuff on right side of console. So all I need is
[branch-name +1 ~0 -0 !]
part from$GitPromptScriptBlock
so I don't have to write that manually using values fromGet-GitStatus
. I almost got it usingand then using this in prompt
However, this still prints a new line at the end. And using plain
.substring
or.split('[')
doesnt work, I assume because of non standard chars in there.I tried to use
Write-VcsStatus
as well but it still adds a new line. Can someone please guide me to get git status part without new line.Cheers
Sorry, not sure if this is the right place but I couldnt find any other way to contact. If there is somewhere else where I should be asking for help, please feel to guide me.