From LedHed's Wiki
Revision as of 10:13, 22 March 2021 by Ledhed (Talk | contribs)

Jump to: navigation, search

Overview

First off I have to say I love you Joseph Napoli, this find changed my life.


One of my biggest complaints about using PowerShell is that Microsoft failed to add some useful command sequences, particularly CTRL+D. If you're a Linux admin you use this key sequence hundreds of times a day. Its by far the easiest way to exit a shell / ssh session.


Enabling EMACS mode in PowerShell

Set-PSReadlineOption -EditMode Emacs

This command enables a user to exit PowerShell with CTRL+D, as well as a few other common key sequences like CTRL+A / CTRL+E (jump to beginning/end of a line).


How to make it persistent

Edit your profile:

echo 'Set-PSReadlineOption -EditMode Emacs' >> $PROFILE


Troubleshooting

If you've not previously setup a PowerShell profile then you may need to follow these steps:

new-item -path $PROFILE -itemtype file -force

Doing the above may produce an error that 'running scripts have been disabled on this system'.
To fix that you can modify your execution policy.
Modify your PowerShell Execution Policy AT YOUR OWN RISK! Run an elevated PowerShell and issue this command:

Set-ExecutionPolicy RemoteSigned

Execution Policy Options:

AllSigned
ByPass
Default
RemoteSigned
Restricted
Undefined
Unrestricted

Please see :'Set-ExecutionPolicy Reference' for more details.


Reference

https://stackoverflow.com/questions/8360215/use-ctrl-d-to-exit-and-ctrl-l-to-cls-in-powershell-console

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.1