How to setup PowerShell with bash shortcuts

Gustavo Adolfo Mejía
4 min readJan 27, 2021

--

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

Steps:

Open PowerShell and run this 4 lines

\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
\> mkdir $(Split-Path $PROFILE)
\> echo "Set-PSReadLineOption -EditMode Emacs" >> $PROFILE
\> & $PROFILE

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

(Get-Host).Version
PowerShell version

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

PowerShell-7.1.1-win-x64.msi

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

windows terminal in the start menu

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

global unique id of PowerShell 7

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

Paste gui as default Profile

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

Get-ExecutionPolicy -List
Undefined Policy to all scopes

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Set RemotedSigned to CurrentUser

Now Let’s create the scope’s folder

mkdir $(Split-Path $PROFILE)
Create PowerShell Scope’s Folder

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

notepad $PROFILE

and paste the configuration Set-PSReadLineOption -EditMode Emacs

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

& $PROFILE

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

Set-PSReadLineKeyHandler -Chord ctrl+j -Function AcceptLine

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.

--

--

No responses yet