How to setup PowerShell with bash shortcuts

TL;DR — Enable Emacs shortcuts (PS6 & PS7)

Steps:

Open PowerShell and run this 4 lines

use Ctrl+p to search into history to check the change was done

Explanation:

  1. Set RemoteSigned into ExcecutionPolicy for CurrentUser
  2. mkdir creates the $PROFILE directory
  3. Paste the Emacs-Edit-Mode into $PROFILE’s file
  4. Reload $PORFILE configuration

Say Hi to PowerShell

PowerShell and command line (CMD) are the default tools in windows, and you has to deal with it. Linux and Mac has a bash terminal. I know that there are another programs like Git bash, but they are not native and that is the reason that I want to focus in PowerShell.

Today PowerShell comes with the version 5 as default, it’s ok but there are some features like &&that are really important and it doesn’t have it. So the first step is to check which version do you have and upgrade it to PowerShell7.

run this code in your terminal

The Major number will shows the version. At this moment, I use the v5.1.

OK, Let’s download the latest version from github

In the Release section, you can find all different releases, and to search it. Check the Assets menu and find the ---x64.msi file

This is a normal installer so you won’t have any problem. Just Execute the Powershell executable. Additionally, windows has some front-end application which integrates the program

Say Hi to «Windows Terminal»

I recommend to use this software, it is the windows terminal, this app is an interface not only for PowerShell, it works with all the terminals. Git Bash, WSL, WSL2, PowerShell, CMD and it is pretty

This app, comes in the windows store, and you can install it from the official store

Now that we has all the programs. lets do the configuration

Open the windows terminal

Open the Settings

Go to the list section and copy the global unique id guid of the PowerShell, is a long string like this. But be careful and don’t confuse with the PowerShell 5, check the comments

Now paste the value into the defaultProfile it is located at the start of the file.

save the file and open the Windows Terminal, if everything was right, it is going to open the PowerShell

PowerShell Configuration

The next step is customize the configuration file. So let’s check the PowerShell Execution permissions

PowerShell restricts some customization by default. This is for security reasons. But don’t worry, it’s no dangerous and you don’t need an administration permission.

If you want to know more about this policy, the official documentation is here

Let’s change the CurrentUser policy from Undefined to RemoteSigned

Now Let’s create the scope’s folder

The $PROFILEis an environment variable which stores the configuration location, We are going to open this file with the notepad program

and paste the configuration Set-PSReadLineOption -EditMode Emacs

Save it, and reload the terminal. You can close and open it or run this command

If everything goes fine. You can use the bash shortcuts in PowerShell.

Extra

C-j as Enter

I really love to Accept line with Ctrl-j and Windows doesn’t have it. So you only need to include this line into the $PROFILE

Cheatsheet

Here is a Webpage where you can find some awesome shortcuts to start

Thats is all the configuration I expect this can helps you.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store