background

Those of you who have used fish or ZSH on Linux or MacOS know how tedious it can be to repeatedly type various commands in Windows. Powershell PSReadLine includes predictive completion and installation, as well as other powershell modules to make your commands more manageable. Final preview, features included:

  1. Auto complete history command, complete word for word
  2. Posh theme
  3. ZLocation Directory jump

The installation process

Download PSReadLine

The powerShell version must be later than 5.1. Run the following command to view the version information

$PSVersionTable
Copy the code

If PowerShell is version 6 or older, the latest PSReadLine is automatically included and no separate installation is required. PSReadLine github

Run the following command to install PSReadLine2.1.0.

Install-Module PSReadLine -RequiredVersion 2.1.0
Copy the code

Considering the domestic network environment, downloading often need to be downloaded successfully

Install-Module PSReadLine -RequiredVersion 2.1.0 -Proxy http://127.0.0.1:7890
Copy the code

Install PSReadLine in offline environment

Some students may not be able to download files in their development environment. The following describes how to install PSReadLine in offline environment

  1. Download the file under normal environment first
Save-Module -Name "PSReadLine" -path "D:\tmp\" -proxy http://127.0.0.1
Copy the code
  1. Copy the files to the development environment
  2. Moves a file to a specified directory
Display the module path
$env:PSModulePath -split ";"
# My computer shows the following
# C:\Users\yuhen\Documents\WindowsPowerShell\Modules
# C:\Program Files\WindowsPowerShell\Modules
# C: \ WINDOWS \ system32 \ WindowsPowerShell \ v1.0 \ Modules
Copy the code

The old PSReadLine is stored in C:\Program Files\WindowsPowerShell\Modules. Just put the downloaded Files into the corresponding directory.

Configuration load file

After the download is complete, you can test whether it works normally by performing the following operations:

Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
Copy the code

The test results are as follows:

Case insensitive, perfect complete history command.

When PowerShell starts, the corresponding configuration is automatically loaded

  1. Check to see if powerShell configuration files exist
Test-path $profile
Copy the code
  1. If false is displayed, create one manually, or if true, modify the corresponding file
New-itemtypeThe file - force$profile
Copy the code
  1. Edit the configuration
notepad $profile
Copy the code
  1. Add the following content
#...+ Import-Module PSReadLine
+ Set-PSReadLineOption -PredictionSource History
Copy the code

Modify verbatim complete shortcut key

Autosuggestion you can use option + → Select the next word as well as → key complete. Now configure the same functionality for Powershell.

Modify $PROFILE as follows:

Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
+ # Alt has special use in Windows, use CTRL key instead
+ Set-PSReadLineKeyHandler -Chord "Ctrl+RightArrow" -Function ForwardWord
Copy the code

Now press CTRL + → to complete word for word, the effect is as follows:

conclusion

Windows Terminal has been around for a while now, and it has nice UI, tabs, etc. With features like Autosuggestion, Windows Shell will be a much better experience.

Use PowerShell tools for the rest

  • Automatic jump directory Autojump /z: github.com/vors/ZLocat…
  • Theme oh – my – posh: ohmyposh. Dev /