目 录CONTENT

文章目录

关于windows powershell命令行的配置

Administrator
2022-10-09 / 0 评论 / 0 点赞 / 28 阅读 / 1900 字 / 正在检测是否收录...

关于windows powershell命令行的配置

很多人都想知道标哥的powershell的命令行怎么会有提示的,就像下面的图一样
image-1665327418121

其实这个很简单的,只需要配置一下就可以了

  1. 在电脑上面打开power shell的窗口,输入下面的命令

    $ notepad $profile
    

    这个时候应该会打开一个文件 ,如果之前有配置的,里面会有内容 ,如果之前没有配置的,应该是一个空文件

  2. 安装powershell的插件

        # 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh
        Install-Module -Name PSReadLine  -Scope CurrentUser
    
        # 2. 安装 posh-git 包,让你的 git 更好用
        Install-Module posh-git  -Scope CurrentUser
    
        # 3. 安装 oh-my-posh 包,让你的命令行更酷炫、优雅
        Install-Module oh-my-posh -Scope CurrentUser
    

    安装过程可能有点慢,好像卡住了一样,但是请耐心等待几分钟。等不及的同学自行搜索科学方法访问 GitHub.
    安装时系统会提问是否继续,不用管它直接输入 A 并回车即可。

  3. 复制标哥的配置进去就可以了

    Import-Module oh-my-posh
     Import-Module posh-git
     Set-PoshPrompt sorin
     Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
     Set-PSReadLineOption -PredictionSource History
     Set-PSReadLineOption -PredictionViewStyle ListView
     Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
     Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
     # Import the Chocolatey Profile that contains the necessary code to enable
     # tab-completions to function for `choco`.
     # Be aware that if you are missing these lines from your profile, tab completion
     # for `choco` will not function.
     # See https://ch0.co/tab-completion for details.
     $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
     if (Test-Path($ChocolateyProfile)) {
       Import-Module "$ChocolateyProfile"
     }
    
0

评论区