Featured image of post Windows Terminal使用及配置教程

Windows Terminal使用及配置教程

常用终端软件Windows Terminal的使用和配置

Windows Terminal

作为微软官方为大家提供的终端软件,Windows Terminal具备非常简约且符合windows风格的界面,对于个人开发者来说是比较方便的工具,但是其因为没有太多设置,都是微软官方提供的比较简单的配置,我们需要下载额外的工具来完善。

提示引擎

Oh My Posh是配置Windos Terminal的主要工具,其不仅支持windows,同时使用linux和macos。安装方法如下:

1
winget install JanDeDobbeleer.OhMyPosh -s winget

或者用scoop直接从github上拉取下载

1
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

提示

在安装好Oh My Posh后,打开PowerShell,按照如下运行:

1
notepad $PROFILE

如果没有该文件,可以直接创建,

1
New-Item -Path $PROFILE -Type File -Force

然后添加这行,

1
oh-my-posh init pwsh | Invoke-Expression

另外我们可以选择自己想要的主题,可以通过如下命令将所有主题展示出来:

1
Get-PoshThemes

找到一个你喜欢用的主题,然后去User/AppData里找到该路径,

1
C:\Users\xxxx\AppData\Local\Programs\oh-my-posh\themes\xxxx.omp.json

然后将上面的改为如下命令就可以应用主题了。

1
oh-my-posh init pwsh --config C:\Users\xxxx\AppData\Local\Programs\oh-my-posh\themes\xxxx.omp.json | Invoke-Expression

字体

官方推荐的Nerd字体,官方提供的字体不多,同样这个网站中提供了终端icon的列表。具体的安装方式可以直接下载,然后拖到本地字体文件夹中安装,也可以使用我们下面说的工具来下载。

1
oh-my-posh font install

选择喜欢的字体下载即可,如果安装了Nerd Font,Windows Terminal需要配置一下(如果是Oh My Posh安装的不需要设置),打开setting中的settings.json,快捷键是CTRL + SHIFT + ,,在profilesdefault中添加font.face

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
    "profiles":
    {
        "defaults":
        {
            "font":
            {
                "face": "MesloLGM NF"
            }
        }
    }
}

定制启动界面

如果想要删除启动界面的那些文字,我们在启动PowerShell时要加上-NoLogo,在Setting-Profiles-Windos PowerShell-Command line启动后添加。

如果想要自定义的话,则打开PowerShell的配置文件,

1
notepad $PROFILE

在最上面添加一下内容即可。

1
2
3
4
5
6
clear
$hello="
定制你自己的内容
"
$hello
"定制你自己的内容"

添加icon

这里使用的也是官方推荐的Terminal-Icons,输入以下命令,

1
Install-Module -Name Terminal-Icons -Repository PSGallery

然后同样进入PowerShell的配置文件,输入notepad $PROFILE,在下面添加如下命令就可以显示出图标。

1
Import-Module Terminal-Icons

添加Posh-git

如果想要将GitPowerShell整合在一起,即可以查看分支和提交记录等,安装如下模块,

1
Install-Module posh-git -Scope CurrentUser

然后继续在PowerShell的配置文件,输入notepad $PROFILE,在下面添加如下命令,

1
Import-Module posh-git
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy