PowerShell7

Pwsh 的安装

Pwsh 的安装:

1
2
3
4
5
6
7
8
# 显示当前 powershell 版本号
$PSVersionTable.PSVersion

# 显示当前最新的可用的版本 正常版和预览版
winget search Microsoft.PowerShell

# 使用 Winget 安装 PowerShell
winget install --id Microsoft.Powershell --source winget

使用 Pwsh(PowerShell7)

win+R 键,打开运行,输入 pwsh,即可

Pwsh 配置

添加自动补全 (无需 Tab 键):

1
2
3
4
5
6
7
8
# 已输入过的命令:
Set-PSReadLineOption -PredictionSource History

# 没有输入过的命令:
Set-PSReadLineOption -ShowToolTips

# 在 pwsh 的属性、快捷方式、目标,用下行代码替代,可永久使用智能提示
"C:\Program Files\PowerShell\7\pwsh.exe" -noe -c "&{Set-PSReadLineOption -PredictionSource History -ShowToolTips}" -WorkingDirectory ~
设置快捷键:
点击终端标题栏的下三角键
点击 设置,找到 操作
找到 新建标签页,修改快捷键为 Ctrl+Alt+T保存 即可

Get-PSReadlineOption 可以查看历史命令的保存路径

安装、使用 oh-my-posh

1
2
3
4
5
6
7
8
9
10
# 安装 oh-my-posh
winget install oh-my-posh

# 添加 ohmyposh 到启动文件中
notepad $PROFILE # 使用记事本打开启动文件
oh-my-posh init pwsh | Invoke-Expression # 把这行代码添加其中保存

Get-PoshThemes # 查看已有的主题

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/neko.omp.json" | Invoke-Expression # 把没加 --config 参数的替换为这行, 添加一个叫 neko 的主题

C:\Users\chpw2\AppData\Local\Programs\oh-my-posh\themes 这个路径添加为名叫 POSH_THEMES_PATH 的新建环境变量

安装字体

Firacode 字体文件下载地址

安装好 Firacode 字体后在终端设置里修改字体,保存退出

安装 Scoop

具体查看 Scoop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 脚本执行策略更改,默认自动同意
Set-ExecutionPolicy RemoteSigned -scope CurrentUser -Force

# 执行安装命令(默认安装在用户目录下,如需更改请执行 “自定义安装目录” 命令)
iwr -useb scoop.201704.xyz | iex


## 自定义安装目录(注意将目录修改为合适位置)
irm scoop.201704.xyz -outfile 'install.ps1'

.\install.ps1 -ScoopDir 'E:\Scoop' -ScoopGlobalDir 'E:\GlobalScoopApps'

# 切换分支到 develop
scoop config scoop_branch develop

# 重新拉取 git
scoop update

# 基本语法
scoop bucket add <别名> <git 地址 >
scoop bucket rm <别名>

scoop bucket add dorado https://gitee.com/scoop-installer/dorado
scoop bucket add scoopet https://gitee.com/scoop-installer/scoopet
scoop bucket add scoopcn https://gitee.com/scoop-installer/scoopcn
scoop bucket add scoop-zapps https://gitee.com/scoop-installer/scoop-zapps
scoop bucket add echo https://gitee.com/scoop-installer/echo-scoop
scoop bucket add aki https://gitee.com/scoop-installer/aki-apps
scoop bucket add siku https://gitee.com/scoop-installer/siku
scoop bucket add lemon https://gitee.com/scoop-installer/scoop-lemon
scoop bucket add cluttered https://gitee.com/scoop-installer/Cluttered-bucket
scoop bucket add iszy https://gitee.com/scoop-installer/scoop-iszy
scoop bucket add tomato https://gitee.com/scoop-installer/tomato
scoop bucket add muggle https://gitee.com/scoop-installer/scoop-muggle

# 查看已知 bucket
scoop bucket known

安装 NeoVim

1
2
3
4
5
6
7
8
# 安装必备软件
scoop install neovim neovide git lazygit gcc ripgrep fd unzip tree-sitter luarocks

# 下载安装 LazyVim 配置
git clone git@github.com:LazyVim/starter $env:LOCALAPPDATA\nvim --depth=1

# 为'nvim'设置别名为'vim'
Set-Alias -Name vim -Value 'nvim'

NodeJS 安装

NodeJS 安装方法:

1
2
3
4
5
6
7
8
9
10
# installs fnm (Fast Node Manager)
winget install Schniz.fnm
# configure fnm environment
fnm env --use-on-cd | Out-String | Invoke-Expression
# download and install Node.js
fnm use --install-if-missing 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.17.0`
# verifies the right npm version is in the environment
npm -v # should print `10.8.2`