익명 05:52

How to achieve HISTCONTROL ignorespace on Windows?

How to achieve HISTCONTROL ignorespace on Windows?

In Bash you can prefix a Space to stop a command from being added to history

  • git commit -am "message"
  • cp existing.file new.file

How to do the same on Windows? A solution for either command or PowerShell would be appreciated.

I keep on smashing Up + Enter in my terminal to build/run, keep shooting myself in the foot.



Top Answer/Comment:

In PowerShell the PSReadLine module is very powerful. To achieve this you can run notepad $PROFILE to open your profile and paste the below snippet

Set-PSReadLineOption -AddToHistoryHandler {
    param($line)

    # Do not store lines starting with whitespaces
    if ($line -match '^\s+') { return $false }

    return $true
}

After this any commands starting with whitespaces will be ignored. You can also use ^ + to match only lines starting with spaces and not tabs

상단 광고의 [X] 버튼을 누르면 내용이 보입니다