Loading

终端美化方案 FluentTermina + oh-my-posh

简介

研究了很久的 windows 平台的终端方案,最终得出了 FluentTerminal 配合 oh-my-posh 的一套终端方案。

效果展示

FluentTerminal

一款美观的终端工具,个人感觉比 Windows Terminal 更加美观。

下载方式:

  1. 直接去微软自带的应用商店里面去搜索下载。
  2. 前往FluentTerminal 项目地址进行下载

设置鼠标右键打开:

新建个记事本,将下面代码粘贴进去保存。随后将.txt更改为.bat,使用管理员权限运行。
无图标方法:

reg add "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\Drive\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f

有图标方法:
图标下载地址
将下载的图标和下面的代码放在同一个文件夹。

copy /y FluentTerminal.ico "%LOCALAPPDATA%\Microsoft\WindowsApps"
reg add "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here" /v icon /t REG_SZ /d "%LOCALAPPDATA%\Microsoft\WindowsApps\FluentTerminal.ico" /f
reg add "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here" /v icon /t REG_SZ /d "%LOCALAPPDATA%\Microsoft\WindowsApps\FluentTerminal.ico" /f
reg add "HKCU\Software\Classes\Drive\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\Drive\shell\Open Fluent Terminal here" /v icon /t REG_SZ /d "%LOCALAPPDATA%\Microsoft\WindowsApps\FluentTerminal.ico" /f
reg add "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here\command" /d "\"%LOCALAPPDATA%\Microsoft\WindowsApps\flute.exe\" new \"%%V\"" /f
reg add "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here" /v icon /t REG_SZ /d "%LOCALAPPDATA%\Microsoft\WindowsApps\FluentTerminal.ico" /f

删除右键打开代码:

reg delete "HKCU\Software\Classes\Directory\shell\Open Fluent Terminal here" /f
reg delete "HKCU\Software\Classes\Directory\Background\shell\Open Fluent Terminal here" /f
reg delete "HKCU\Software\Classes\Drive\shell\Open Fluent Terminal here" /f
reg delete "HKCU\Software\Classes\LibraryFolder\Background\shell\Open Fluent Terminal here" /f
del %LOCALAPPDATA%\Microsoft\WindowsApps\FluentTerminal.ico

使用oh-my-posh对终端进行美化

oh-my-posh官方文档

使用官方给的方法,在powershell中进行安装。

winget install JanDeDobbeleer.OhMyPosh -s winget

安装后重启终端,使用以下命令初始化。(有时候会出现函数报错,这时需要重启一下电脑)

oh-my-posh init pwsh | Invoke-Expression

初始化之后可能会发现,字体乱码,需要前往 Nerd Font 安装该系列字体。

也可以使用管理员权限运行如下命令来安装字体。

oh-my-posh font install

字体安装后,在相应的终端工具中调整字体。

设置完之后,发现再次打开终端时并不能成功加载 oh-my-posh。我们需要给 powershell 增加初始化脚本。

使用如下命令查看个人配置文件路径。

$profile

在对应显示的地址去创建个人配置文件。

在个人配置文件中写下如下初始化命令。

oh-my-posh init pwsh --config ~/.jandedobbeleer.omp.json | Invoke-Expression

然后使用管理员权限运行以下命令来允许 powershell 每次打开时执行初始化脚本。

set-ExecutionPolicy RemoteSigned

这样再打开终端,就直接可以显示了。

打开终端时,一般会有一些提示显示前面,我们可以再终端工具的设置里启动时参数加上-nologo即可删除启动时的提示。

针对于主题修改,我们可以使用如下命令来预览主题。

Get-PoshThemes

在预览主题的最下面,会有显示主题在我们本机的地址代码示例。

我们将示例地址代码取代我们在 powershell 初始化脚本中的代码,将代码中对应的主题名字替换成我们想换的主题名即可。

比如我们将想用1_shell主题,只需要对照上图中的地址信息修改成如下即可。

oh-my-posh init pwsh --config C:\Users\brokyz\AppData\Local\Programs\oh-my-posh\themes/1_shell.omp.json | Invoke-Expression
posted @ 2022-06-29 19:50  brokyz  阅读(458)  评论(0编辑  收藏  举报