起因
Windows
平台下的默认的终端是究极远古老祖cmd
和powershell 5
(以下简称PS
)。后来本人在一次偶然的情况遇上了PS 7
。
因为up主在vscode
中使用copilot的时候,能够实现在输入部分不完整指令的情况下,能够出现指令的待选列表,就像是code时,IDE
提供的LSP
补全一样,非常好的好用(‾◡◝)

但是up在后来使用cursor
的时候却发现,同样在启用terminal.integrated.suggest.enabled
设置时,我的cursor
却不能够正常开启该功能🥲
后来查阅资料发现,cursor
对于这项功能的支持,只适用于PS 7
(截至截稿时)。所以up通过winget
包管理工具安装了PS 7
。
1
| winget install --id Microsoft.PowerShell --source winget
|
在使用PS 7
的时候发现powershell
的预测性输入非常的好用,只需要按下→
即可选中,同时不耽误原本的基础的Tab
自动补全。~( ̄▽ ̄)~*
脚本
通过改写$PROFILE
文件实现自启动的一些功能。
这里的edit是一种终端编辑器,大家可以换成记事本或者其他编辑器
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| $OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() $Local:word = $wordToComplete.Replace('"', '""') $Local:ast = $commandAst.ToString().Replace('"', '""') winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } }
function touch { param($name) New-Item -Path $name -ItemType File -Force }
$script:PoshGitLoaded = $false function git { if (-not (Get-Module posh-git)) { Import-Module posh-git -ErrorAction SilentlyContinue if (-not $script:PoshGitLoaded) { Write-Host "[posh-git 已启用]" -ForegroundColor Green $script:PoshGitLoaded = $true } } & git.exe @Args }
function Enable-EnvProxy { $proxy = "http://127.0.0.1:7890" $env:http_proxy = $proxy $env:https_proxy = $proxy Write-Host "环境变量代理已开启:$proxy" }
function Disable-EnvProxy { Remove-Item Env:http_proxy -ErrorAction SilentlyContinue Remove-Item Env:https_proxy -ErrorAction SilentlyContinue Write-Host "环境变量代理已关闭" }
Enable-EnvProxy
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\agnoster.minimal.omp.json" | Invoke-Expression
|
现在实现了一下功能:
- 终端自动设置的代理端口
- 使用
UTF-8
编码
winget
的Tab
补全
- 按需启动
Git
模块(在第一次输入git
指令的时候才开启)
- 方便的
touch
函数
oh-my-posh
的主题(已被注释)
希望能够帮到大家(≧︶≦))( ̄▽ ̄ )ゞ