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 平台中的一个包管理器。
安装
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
命令安装PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
-
使用 scoop 安装
scoop install posh-git Add-PoshGitToProfile
oh-my-posh(https://github.com/JanDeDobbeleer/oh-my-posh)
安装
Install-Module oh-my-posh -Scope CurrentUser
oh-my-posh 中的一些主题可能需要 powerline 字体,安装过程参考https://github.com/powerline/fonts。
Get-ChildItemColor(https://github.com/joonro/Get-ChildItemColor)
安装
Install-Module -AllowClobber Get-ChildItemColor
一个示例配置文件
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
配置后的效果图如下: