Page 1 of 1
Move flashing prompt sign away from left edge of PowerShell window
Posted: 14 Sep 2023 07:35
by DOSadnie
Is there a way to move the prompt sign in PowerShell [an also CMD] window more toward middle / right side of a it? So that a new empty line would flash it prompt sign as not being adjacent to the left edge of the window when awaiting for input from user?
This almost does what I need
Code: Select all
# -The countdown function
function Start-Countdown {
$Countdown = 2
while ($Countdown -gt 0) {
Write-Host ("Countdown: $Countdown seconds") -NoNewline
Start-Sleep -Seconds 1
$Countdown--
Write-Host "`r" -NoNewline
}
}
# Start the countdown
Start-Countdown
# Clear the countdown line
Write-Host "`r"
# Modifications of prompt
$Prompt = " " * 2 + ""
Write-Host $Prompt -NoNewline
# Wait for input from user
Read-Host ""
as it shows
ppp:p_
instead of
pppp_
[where each >>p<< represent a white pause]
Where is that splitting >>:<< sign coming from? And more importantly: how to get rid of it?
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 21 Sep 2023 01:46
by DOSadnie
I have managed to co come up with a partial solution
This script
Code: Select all
$COUNTDOWN = 3
Write-Host
Write-Host " Endng in"
Write-Host
Write-Host " $COUNTDOWN"
Write-Host
Write-Host " seconds"
Write-Host
Start-Sleep -Seconds $COUNTDOWN
Write-Host
Write-Host
Write-Host " Script has been executed"
Write-Host
Write-Host "`r" # This clears the line
$Prompt = " " * 2 + " " # That separate single white space at the end of this line can be entirely removed or changed into whatever sign or text is desired
Write-Host $Prompt -NoNewline
Read-Host
will leave user with the third / last prompt line / sign being moved away from the left edge of the window - but so far I have been unsuccessful with making look like so all of the prompt signs [the initial one and the second during the countdown in this new example from this post]
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 22 Oct 2023 09:02
by DOSadnie
Does anyone have any ideas about how to do this?
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 22 Oct 2023 09:30
by ShadowThief
Are you just looking for prompt $S$S$P$G?
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 18 Nov 2023 11:45
by DOSadnie
If you mean replacing line
with either
Code: Select all
$Prompt = "$S$S$P$G"
$Prompt = $S$S$P$G
$Prompt $S$S$P$G
then this does not work
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 28 Dec 2023 03:24
by DOSadnie
DOSadnie wrote: ↑18 Nov 2023 11:45
If you mean replacing line
[...]
Well, did you?
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 18 Feb 2024 03:39
by DOSadnie
I made basic tests files with just
Code: Select all
function prompt {
"$(' ' * 3)$(Get-Location)> "
}
Read-Host
Code: Select all
function prompt {
Write-Host (" " * 3) -NoNewline
return " $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
}
Read-Host
but they all were showing to me the prompt sign adjacent next to left edge of PS window
How else can I try to move the prompt to the right?
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 18 Feb 2024 09:00
by Squashman
Seems to work just fine for me.
Code: Select all
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Users\Squashman> function prompt {Write-Host (" " * 10) -NoNewline}
PS>function prompt {Write-Host (" " * 15) -NoNewline}
P> function prompt {Write-Host (" " * 20) -NoNewline}
PS>
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 22 Jun 2025 07:11
by DOSadnie
If I open PowerShell console as Administrator and paste in
Code: Select all
function prompt {Write-Host (" " * 3) -NoNewline}
and press Enter, then I do get what I want i.e. the prompt line moved 3 space signs away from the left edge of that window
But if I will save it as a PS1 file
Code: Select all
function prompt {Write-Host (" " * 3) -NoNewline}
Read-Host
and execute it, then the PowerShell window will show the prompt sign in its default position i.e. adjacent to left edge
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 22 Jun 2025 08:32
by DOSadnie
I did some further tests. And unfortunately when trying to come up with a workaround utilizing re-opening of PowerShell window and / or temporary file, I stumbled upon the same issue as with my other script [
viewtopic.php?f=3&t=12105&p=71349#p71346]: the inability to stop HIPS of COMODO from asking for the same permission every time I execute it, despite green-lighting it and telling it to remember my choice
So this issue must be dealt with within one file and one console window
Re: Move flashing prompt sign away from left edge of PowerShell window
Posted: 23 Jun 2025 06:26
by DOSadnie
[The below is something that should rather be struck from the record - because it is most likely not true and to which current claim attest my later findings]
So far I have a limited success:
if I put this at the beginning of multi-step / multi-prompt script
Code: Select all
$global:NextPromptPrefix = ''
function prompt {
if ($global:NextPromptPrefix) {
$prefix = $global:NextPromptPrefix
$global:NextPromptPrefix = ''
} else {
$prefix = ''
}
return "$prefix$((Get-Location).Path)> "
}
function Set-NextPromptPrefix {
param([string]$prefix)
$global:NextPromptPrefix = $prefix
}
then if I put this also this at the end of an section
Code: Select all
Set-NextPromptPrefix 'THIS TEXT WILL NOT BE DISPLAYED DUE TO WHATEVER GLITCH IN THE CODE - BUT IT NEVERTHELESS CAUSES SOMETIMES THE DESIRED BEHAVIOR OF THE PROMPT'
the new line sometimes inherits the position of the prompt from the previous one [and the position in previous one is, in most cases, a setting can more or less control]
So either this must be polished - or a different approach is needed