安装 PowerShell
官方安装教程
查找 PowerShell 版本
1winget search Microsoft.PowerShell
Name Id Version Source
---------------------------------------------------------------
PowerShell Microsoft.PowerShell 7.5.1.0 winget
PowerShell Preview Microsoft.PowerShell.Preview 7.6.0.4 winget
进行安装
1winget install --id Microsoft.PowerShell --source winget
1winget install --id Microsoft.PowerShell.Preview --source winget
更新操作
1winget upgrade Microsoft.PowerShell
配置 PowerShell
首次在系统上安装 PowerShell 时,配置文件脚本文件和它们所属的目录不存在。 以下命令创建“当前用户,当前主机”配置文件脚本文件(如果不存在)。
1if (!(Test-Path -Path $PROFILE)) {
2 New-Item -ItemType File -Path $PROFILE -Force
3}
添加个性化设置
1function desk { Set-Location "C:\Users\docke\Desktop" }
2function gitl { git log --oneline --graph --decorate }
3function ep { code $PROFILE }
4function hosts { notepad C:\Windows\System32\drivers\etc\hosts }
5function vim { nvim $args }
6
7Set-PSReadLineOption -PredictionSource History, Plugin
8Set-PSReadLineOption -PredictionViewStyle ListView
9Set-PSReadLineOption -EditMode Windows
10Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
安装 Windows 终端
官方安装教程
https://learn.microsoft.com/zh-cn/windows/terminal/install
根据页面自行定制化设置即可,需确认好终端已将前边最新 PowerShell 设置为默认值。
安装 Nerd Fonts 字体
官网: https://www.nerdfonts.com/
Nerd Fonts 是一个为开发者量身定制的字体资源网站,通过将编程字体与图标字体结合,提供了一种功能强大且美观的方式来优化开发环境。无论是提升终端的视觉效果,还是增强代码的可读性和个性化,它都是一个非常有价值的工具。如果你是程序员或终端用户,这个网站值得一试。
其中我个人比较喜欢使用 JetBrainsMono Nerd Font。
安装 Oh My Posh
官方安装教程
推荐 winget 安装。
安装后在 PowerShell 配置文件中增加启动项,这里使用了自带的 jandedobbeleer 主题,这也是作者自己的主题。
1oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression
创建或修改 $PROFILE
文件后,需要重载它以应用更改。运行以下命令:
1. $PROFILE
Oh My Posh 同样支持使用远程配置(但个人实测会有卡顿),本地配置会更加流畅。
个人配置
1{
2 "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
3 "console_title_template": "{{ .Shell }} in {{ .Folder }}",
4 "final_space": true,
5 "version": 3,
6 "transient_prompt": {
7 "background": "transparent",
8 "foreground": "#ffffff",
9 "template": "{{ .Shell }}> "
10 },
11 "blocks": [
12 {
13 "type": "prompt",
14 "alignment": "left",
15 "segments": [
16 {
17 "type": "path",
18 "style": "diamond",
19 "leading_diamond": "\ue0b6",
20 "trailing_diamond": "\ue0b0",
21 "foreground": "#ffffff",
22 "background": "#ff479c",
23 "properties": {
24 "folder_separator_icon": " \ue0b1 ",
25 "home_icon": "~",
26 "style": "unique"
27 },
28 "template": " \uea83 {{ .Path }} "
29 },
30 {
31 "type": "executiontime",
32 "style": "plain",
33 "foreground": "#ffffff",
34 "background": "#83769c",
35 "properties": {
36 "always_enabled": true
37 },
38 "template": "<transparent>\ue0b0</> \ueba2 {{ .FormattedMs }}\u2800"
39 },
40 {
41 "type": "status",
42 "style": "diamond",
43 "trailing_diamond": "\ue0b4",
44 "foreground": "#ffffff",
45 "background": "#00897b",
46 "background_templates": ["{{ if gt .Code 0 }}#e91e63{{ end }}"],
47 "properties": {
48 "always_enabled": true
49 },
50 "template": "<parentBackground>\ue0b0</> \ue23a "
51 }
52 ]
53 },
54 {
55 "type": "rprompt",
56 "segments": [
57 {
58 "type": "sysinfo",
59 "style": "plain",
60 "foreground": "#ffffff",
61 "template": "\uefc5 {{ round .PhysicalPercentUsed .Precision}}%"
62 }
63 ]
64 }
65 ]
66}
安装 Scoop
Scoop 是一款适用于 Windows 的命令行包管理器,类似于 Linux 上的 apt 或 macOS 上的 Homebrew。它可以帮助用户快速安装和管理软件,尤其适合开发者或喜欢命令行操作的用户。
主要参考此仓库教程: https://github.com/ScoopInstaller/Install
进行高级安装,可以下载安装程序并手动执行它,并附带参数。
1irm get.scoop.sh -outfile 'install.ps1'
可以将 Scoop 安装到自定义目录,配置 Scoop 将全局程序安装到自定义目录,并在安装过程中绕过系统代理。
1.\install.ps1 -ScoopDir 'D:\Applications\Scoop' -ScoopGlobalDir 'F:\GlobalScoopApps' -NoProxy