Windows10 Powershell 设置

首先Powershell的用户配置在用户目录的Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1文件中。

美化需要安装一些插件,在windows平台上脚本的执行策略必须是RemoteSigned或者Unrestricted,可以使用Get-ExecutePolicy检查powershell脚本的执行策略。如果在安装的过程中出现脚本执行策略的问题,可以用Set-ExecutionPolicy设置脚本执行策略,例如 ,可以用如下命令 Set-ExecutionPolicy Unrestricted -Scope CurrentUser将当前用户的脚本执行策略设置为Unrestricted

推荐的插件

scoop(https://github.com/lukesampson/scoop)

scoop 是windows平台中的一个包管理器。

安装

1
2
3
4
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# 或者使用
iwr -useb get.scoop.sh | iex
posh-git(https://github.com/dahlbyk/posh-git)

安装

  • 使用Install-Module命令安装

    1
    
    PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
    
  • 使用scoop 安装

    1
    2
    
    scoop install posh-git
    Add-PoshGitToProfile
    
oh-my-posh(https://github.com/JanDeDobbeleer/oh-my-posh)

安装

1
Install-Module oh-my-posh -Scope CurrentUser

oh-my-posh 中的一些主题可能需要powerline字体,安装过程参考https://github.com/powerline/fonts。

Get-ChildItemColor(https://github.com/joonro/Get-ChildItemColor)

安装

1
Install-Module -AllowClobber Get-ChildItemColor

一个示例配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
chcp 65001
Import-Module posh-git
Import-Module oh-my-posh
If (-Not (Test-Path Variable:PSise)) {  # Only run this in the console and not in the ISE
    Import-Module Get-ChildItemColor
    
    Set-Alias ll Get-ChildItem -option AllScope
    Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
}

Set-Alias pwd Get-Location -option AllScope

#Set-Theme Paradox
Set-Theme Honukai

配置后的效果图如下:

Nsxg0K.png