安装windows terminal

进入microsoft store 安装windows terminal

beautify

  1. # 美化要点:
  2. 1. 改主题 Oh-My-Posh
  3. 2. 改颜色主题
  4. 3. 换字体

install scoop

  1. # 保证允许本地脚本的执行
  2. set-executionpolicy remotesigned -scope currentuser
  3. # install scoop
  4. iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

install font

  1. # 搜索 nerd fonts,这里选择是的FantasqueSansMono这个字体
  2. scoop search FantasqueSansMono-NF
  3. # 添加 nerd fonts 源
  4. scoop bucket add 'nerd-fonts'
  5. # 安装 nerd fonts
  6. scoop install FantasqueSansMono-NF

install oh-my-posh (similar with oh-my-zsh)

  1. # 1. 安装 choco
  2. Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  3. # 2. 安装ConEmu
  4. choco install ConEmu
  5. # 3. 安装 posh-git 和 oh-my-posh
  6. Install-Module posh-git -Scope CurrentUser
  7. Install-Module oh-my-posh -Scope CurrentUser
  8. # 4. 设置 Powershell 的 profile
  9. if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
  10. notepad $PROFILE
  11. # 5. 粘贴以下内容进 profile 文件
  12. Import-Module posh-git
  13. Import-Module oh-my-posh
  14. Set-Theme Paradox

optimize ls

  1. # 1. 直接在powershell里运行(如果运行失败请检查是否安装 PowerShellGet):
  2. Install-Module Get-ChildItemColor
  3. # 或者
  4. # git 安装(上面成功了,就不需要再用 git 安装)
  5. git clone https://github.com/joonro/Get-ChildItemColor.git
  6. # 2. 激活
  7. Import-Module Get-ChildItemColor

sample profile config

  1. Import-Module Get-ChildItemColor
  2. $env:PYTHONIOENCODING="utf-8"
  3. # Remove curl alias
  4. If (Test-Path Alias:curl) {Remove-Item Alias:curl}
  5. If (Test-Path Alias:curl) {Remove-Item Alias:curl}
  6. # Remove-Item alias:ls -force
  7. Set-Alias l Get-ChildItemColor -option AllScope
  8. Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
  9. function GitLogPretty {
  10. git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
  11. }
  12. function PrettyLS {
  13. colorls --light -A
  14. }
  15. function GitStat {git status}
  16. function GoBack {Set-Location ..}
  17. function GetMyIp {curl -L tool.lu/ip}
  18. function UpdateScoop {scoop update; scoop update *}
  19. function UpdateChoco {choco upgrade chocolatey}
  20. Import-Module posh-git
  21. Import-Module oh-my-posh
  22. # $DefaultUser = 'spenc'
  23. # Setup other alias
  24. Set-Alias open Invoke-Item
  25. Set-Alias .. GoBack
  26. Set-Alias glola GitLogPretty
  27. Set-Alias gst GitStat
  28. Set-Alias myip GetMyIp
  29. Set-Alias pls PrettyLS
  30. # Set theme
  31. Set-Theme robbyrussell
  32. Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

安装 oh-my-posh

我们需要先以管理员权限启动 PowerShell,以便执行安装操作。(具体是在开始按钮上点击右键,选择“Windows PowerShell (管理员)”。
然后,运行命令以安装 posh-git,这是 oh-my-posh 的依赖。

  1. Install-Module posh-git -Scope CurrentUser

如果此前没有安装 NuGet 提供程序,则此时会提示安装 NuGet;如果此前没有开启执行任意脚本,此处也会提示执行脚本。如果没有权限执行脚本,可能需要先执行 Set-ExecutionPolicy Bypass
windows terminal 更改为Oh-my-zsh - 图1
接下来,运行命令以安装 oh-my-posh 本身。

  1. Install-Module oh-my-posh -Scope CurrentUser

自此,oh-my-posh 安装完毕。
启用模组并设置主题
接下来,我们需要启用安装的模组。启用模组的命令是:
Import-Module oh-my-posh
但是运行Import-Module oh-my-posh时多数情况下会提示系统禁止运行脚本。
windows terminal 更改为Oh-my-zsh - 图2
解决办法如下:
详细说明
Restricted 执行策略不允许任何脚本运行。
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。
本主题说明如何运行所选未签名脚本(即使在执行策略为 RemoteSigned 的情况下),还说明如何对
脚本进行签名以便您自己使用。
下面我们允许运行签名脚本
———————————————-
首次在计算机上启动 Windows PowerShell 时,现用执行策略很可能是 Restricted(默认设置)。Restricted 策略不允许任何脚本运行。
若要了解计算机上的现用执行策略,请键入:
get-executionpolicy
若要在本地计算机上运行您编写的未签名脚本和来自其他用户的签名脚本,请使用以下命令将计算机上的
执行策略更改为 RemoteSigned:
set-executionpolicy remotesigned
执行“set-ExecutionPolicy RemoteSigned ”:

执行策略更改
执行策略可以防止您执行不信任的脚本。更改执行策略可能会使您面临 about_Execution_Policies
帮助主题中所述的安全风险。是否要更改执行策略?
[Y] 是(Y) [N] 否(N) [S] 挂起(S) [?] 帮助 (默认值为“Y”): y
windows terminal 更改为Oh-my-zsh - 图3
上图可以看出已成功更换为Remotesigned,这样就可以愉快的玩起来了
输入Import-Module oh-my-posh
windows terminal 更改为Oh-my-zsh - 图4
成功。~~~
但是,我们期望的是每次打开 PowerShell 都能够启用这个模组,所以我们需要设置 profile 文件让它自动启用。
输入: $profile 可以让 PowerShell 告诉我们这个文件的路径是什么。当然下图是我的路径,读者的默认在文档路径里的 PowerShell 文件夹下。
windows terminal 更改为Oh-my-zsh - 图5
我们需要编辑这个文件上图路径:c:\Users.…….(如果没有,手动创建一个),然后在里面写下:Import-Module oh-my-posh
接下来,新打开 PowerShell(不需要管理员权限)时就会提示加载了这个文件:
windows terminal 更改为Oh-my-zsh - 图6
测试效果:输入set-theme设置主题,这里不要按加车, 按tap 可以自动匹配主题名了。
windows terminal 更改为Oh-my-zsh - 图7

set-theme robbyrussell