11

When I use vagrant on Windows I will sometimes find that newlines aren't respected properly. This is typically after doing a vagrant ssh. So text ends up looking like

This machine with the name 'default' was not found 
                                                   configured for this environment.

In bash when this kind of terminal goofup happens I can run reset and it clears and resets the terminal settings. How can I do something similar in Powershell/CMD and not have to kill the window and start a new powershell/cmd session?

1
  • 1
    Actually, "reset" does something else (reset the console settings, including codepages etc). Usually you use "reset" when dumping garbage from a binary files renders your console unusable. If you just want to clear the screen, use "clear" (or press Ctrl+L). Commented Jul 11, 2019 at 12:54

2 Answers 2

4

While not a replacement for the Linux reset command, this PowerShell script will update your PowerShell terminal window buffer width to match the window width, which may fix the alignment issues you mentioned.

I use this script to remove the horizontal scroll bar that appears when I resize down the window horizontally.

function reset {
    Set-Buffer-Width-To-Screen-Width
    Clear-Host
}

function Set-Buffer-Width-To-Screen-Width {
    $h = Get-Host
    $ui = $h.UI.RawUI
    $bufferSize = $ui.BufferSize
    $windowSize = $ui.WindowSize
    $bufferSize.Width = $windowSize.Width
    $ui.BufferSize = $bufferSize
}
2

Use CLS in both the command prompt and PowerShell.

Note: In PowerShell, CLS is technically an alias of the command Clear-Host.

CLS Clear the screen - Windows CMD - SS64

Syntax: CLS

If CLS is redirected to file, console or executed through FOR /F it will print a line feed character (ASCII 10).

Errorlevels:
If the screen is successfully cleared %ERRORLEVEL% = unchanged (this is a bug) If a bad switch is given = 1

 

Clear-Host - PowerShell - SS64 Clear-Host

Clear the screen.

Syntax: Clear-Host

Standard Aliases for Clear-Host: clear, cls

1
  • 13
    This just clears the screen. It doesn't reset the terminal settings. reset on linux does more than just clear the screen?
    – IguyKing
    Commented Jul 20, 2017 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .