📜 ⬆️ ⬇️

PSReadLine install syntax highlighting in PowerShell console

Owners of windows 10 can enjoy syntax highlighting in PowerShell. In previous versions, the backlight will not appear even if you install WMF5. It is implemented by the PSReadLine module. This module allows you to make different Emac lights like Vim, add commands, etc., add a search in the history, your own shortcuts, etc. The following describes how to set the backlight in the PowerShell console for previous versions of windows.

1. installation on Win 8.1 and 2012R2 if you already have WMF5 installed
The first thing you need to do is download the backlight module from the OneGet storage with the Find-Package cmdlet. If it has not been used before, you will be asked to download and install the NuGet package manager.

We drive teams below, we answer all questions in the affirmative
Find-Package PSReadLine Install-Module PSReadLine Import-Module PSReadLine 

syntax highlighting
having oneget makes life easier

2. Installation in Win 8.1 with PowerShell 4
need to download PSReadLine.zip from GitHub.
After you check whether the lock is removed from the downloaded file (otherwise you may get an error when trying to run the script), to do this, open the file properties and if there is an "unlock" button, press it
alternate thread unlocking
This is just a module, then we act as when installing any module, copy it to your modules folder. If you have not created such a folder yet, you must create it
')
 cp $env:USERPROFILE\Downloads\PSREadline\* $env:USERPROFILE\Documents\WindowsPowerShell\Modules\PSReadLine\ 


PSReadLine installation
To install, run the console under the administrator
set script execution permissions
import the module
 Import-Module PSReadLine 

if you do not see the error messages, then everything is done correctly and the module is started

last you can add automatic import of the module each time you start the console
for this you need to add the import command to your profile. Since PS4 module does not work well in PowerShell ISE. It is recommended to leave the import only for the console. there is no such problem for PowerShell 5, the module also works in ISE without errors

 if ($host.Name -eq 'ConsoleHost') { Import-Module PSReadLine } 


Now you can enter Get-PSReadlineKeyHandler and see which default shortcuts are defined.

Source: https://habr.com/ru/post/303986/


All Articles