TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

windows terminal 美化

Laughing博主
2020-12-13
/
0 评论
/
2,014 阅读
/
366 个字
/
百度已收录
12/13
本文最后更新于2024年03月18日,已超过185天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

Windows终于可以告别丑陋的cmd命令了。

安装步骤

一、安装Windows Terminal

打开Microsoft Store,搜索terminal,安装即可

注意:安装windows terminal需要1909及以上版本

二、复制以下配置文件

  1. 打开terminal,执行
notepad $PROFILE
  1. 如果提示路径找不到之类的错误,先执行以下命令
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
  1. 在打开的notepad中,粘贴以下内容

    Import-Module Get-ChildItemColor
    
    $env:PYTHONIOENCODING="utf-8"
    # Remove curl alias
    If (Test-Path Alias:curl) {Remove-Item Alias:curl}
    If (Test-Path Alias:curl) {Remove-Item Alias:curl}
    # Remove-Item alias:ls -force
    Set-Alias l Get-ChildItemColor -option AllScope
    Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
    
    function GitLogPretty {
      git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
    }
    
    function PrettyLS {
      colorls --light -A
    }
    
    function GitStat {git status}
    
    function GoBack {Set-Location ..}
    
    function GetMyIp {curl -L tool.lu/ip}
    function UpdateScoop {scoop update; scoop update *}
    
    function UpdateChoco {choco upgrade chocolatey}
    
    Import-Module posh-git
    Import-Module oh-my-posh
    # $DefaultUser = 'spenc'
    
    # Setup other alias
    Set-Alias open Invoke-Item
    Set-Alias .. GoBack
    Set-Alias glola GitLogPretty
    Set-Alias gst GitStat
    Set-Alias myip GetMyIp
    Set-Alias pls PrettyLS
    
    # Set theme
    Set-PoshPrompt PowerLine
    # Set-Theme robbyrussell
    
    Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

可能会有提示报错之类的,不急,我们再继续安装关联的内容。


好多文章,里面写的Set-Theme,其实这个是错误的,正确的应该是Set-PoshPrompt

三、安装scop

安装scop之前,我们需要确保githubcontnet能正常访问,否则会报错,如果githubcontent无法访问,请参考https://www.xiangcaowuyu.net/blog/resolve-inaccessibility-rawgithubusercontentcom-problem-dns-pollution.html进行配置。

  1. 执行

    Set-ExecutionPolicy RemoteSigned -scope CurrentUser
  2. 安装

    Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

四、安装字体

如果电脑没有安装git,需要先安装git

scoop install git

依次执行每行命令,安装字体即可(速度可能比较慢,耐心等待即可)

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

五、安装Choco

  1. 管理员方式运行Windows Terminal
  2. 执行命令

    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

六、安装oh-my-posh

依次执行以下命令

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

七、优化ls命令

  1. 安装get-childitemcolor
choco install get-childitemcolor
  1. 引用get-childitemcolor
Import-Module Get-ChildItemColor

八、其他配置修改

打开设置界面

找到default节点,粘贴以下内容

 "fontFace": "Cascadia Code", // 字体
            "useAcrylic": true, // 是否开启透明度
            "acrylicOpacity": 0.7, // 面板透明度
            "colorScheme": "One Half Dark", // 颜色主题
            "backgroundImage": "C:\\Users\\laughing\\Pictures\\terminal.jpeg",
            "backgroundImageOpacity": 0.3, // 背景图片透明度(我这里是预留的,我没有设置背景图片)
            "backgroundImageStretchMode": "fill" // 背景图片填充方式

九、背景图

背景图大家可以随意设置,我设置的背景图是下面这个

朗读
赞(1)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/devtools/windows-terminal-beautification.html(转载时请注明本文出处及文章链接)

评论 (0)
  1. xiaoli 闲逛
    MacOS · Google Chrome

    为什么审核没通过

    2018-06-29 回复