失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 告别黑白CMD PowerShell + Windows Terminal 终端美化

告别黑白CMD PowerShell + Windows Terminal 终端美化

时间:2020-12-21 01:11:56

相关推荐

告别黑白CMD  PowerShell + Windows Terminal 终端美化

Windows Terminal 只支持 Windows 1903 以上的版本,如果你的电脑未升级,可以退出浏览了。

软件介绍与安装

在微软商店下载下载PowerShellWindows Terminal

或者在GitHub上下载,点击直达 PowerShell 和 Windows Terminal。

下载压缩包即可,注意,如果你下载的的是第一个,由于后缀名是 .msixbundle, 需要使用下面命令安装:

Add-AppxPackage ./Microsoft.WindowsTerminal_1.0.1401.0_8wekyb3d8bbwe.msixbundle

安装Git,点击直达下载

主题美化

1.打开PowerShell, 安装 Posh - git 和 Oh - my - posh。

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

安装过程中需要输入Y

2.安装完成后,继续使用PowerShell 执行如下命令

if (!(Test-Path -Path $PROFILE )) {New-Item -Type File -Path $PROFILE -Force }notepad $PROFILE

弹出一个记事本,出现下面内容:

Set-Theme 后面跟的就是你设置的主题名字。

Ctrl+s 保存后,关闭记事本,重启PowerShell。

安装主题

查看Oh-my-posh所有主题:

Get-Theme

选择你想要的主体,然后使用下面命令查看主题效果:

Set-Theme 主题名字

挑选好后重新使用下面命令

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }notepad $PROFILE

在弹出的记事本中修改主题名称即可保存修改。

主题参考推荐: 5 个 PowerShell 主题,让你的 Windows 终端更好看

安装字体

当你设置好主题后,发现有些文字或符号乱码或者没有效果不佳,请点击下载 Powerline 字体并安装到本地。

快捷使用步骤:

# 克隆仓库git clone /powerline/fonts.git --depth=1# 切换目录cd fonts# 安装字体./install.sh# // 删除仓库cd ..rm -rf fonts

安装好字体后,发现还是没有效果,打开settings.json,在默认设置中添加中的"fontFace"项,注意要更改为其显示的正式名称。

"fontFace": "字体名字"

如:

"fontFace": "Cascadia Code PL"

出效果了:

个别主题还是显示不正常,形态各异,因为 Powerline 字体对某些字符不支持,所以无法正常显示包含其他字形的主题,解决办法有两种,选其中一种即可:

第一种方式:

- 使用 Nerd Fonts 字体

在 Nerd Fonts 下载自己喜欢的字体

如 Caskaydia Cove、DejaVu Sans Mono、Fira Code、Inconsolata LGC、JetBrains Mono、Ubuntu等。

下载安装字体后,在settings.json中的"fontFace"项为设置Nerd字体即可,注意要更改为其显示的正式名称,如:

"fontFace": "DejaVu Sans Mono"

第二种方式、下载安装 Cascadia Code 字体并设置。

配色方案

配色方案的网站

Windows Terminal Themes TerminalSplash Iterm2-color-schemes 如果希望将 Dracula 的配色方案添加进入 Windows Terminal:可以到 iTerm2-Color-Scheme - Windows Terminal 仓库下找到自己想要使用的配色方案,将JSON格式的配色复制进入 Windows Terminal 配置文件即可。比如我希望添加 Dracula 配色方案,只需要访问 Dracula.json,将代码部分复制,并粘贴到 Windows TerminalJSON配置文件中即可。 ColorTool

微软官方提供了更换 PowerShell 配色的工具:ColorTool.exe,该工具支持 iTerm 主题(以 .itermcolors 结尾的主题文件)。

先在 ColorTool 在 GitHub 的 Release 页面 下载 ColorTool 至本地,并解压

然后,打开 Windows 默认终端,定位至刚刚解压好有ColorTool.exe的下载文件夹

通过下面这个命令来查看默认有哪些自带的主题供我们使用:

$ ColorTool.exe -s

我们就可以通过ColorTool.exe <主题名称>命令来预览我们当前使用的终端主题,比如:

$ ColorTool.exe solarized_dark.itermcolors

使用下面的命令应用主题:

$ ColorTool.exe -d <主题名称>

Windows Terminal 自定义配置

配置 JSON 文件即可,加入以下参考配置,可自行修改,一定要符合json的内容格式,不然会报错,还有就是图片的的路径要与己系统对应:

下面是我的配置文件:

{"$schema": "https://aka.ms/terminal-profiles-schema",// Add custom actions and keybindings to this array.// To unbind a key combination from your defaults.json, set the command to "unbound".// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings"copyFormatting": "none","copyOnSelect": false,"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}","launchMode": "default","profiles": {// 默认配置,将会应用全部"defaults": {// 背景图片地址"backgroundImage": "D:\\Picture\\Win10\\ai.png","backgroundImageOpacity": 0.5,"closeOnExit": "graceful",// 颜色方案"colorScheme" : "Andromeda", //光标颜色"cursorColor": "#FFFFFF",//光标形状(默认为bar,即条状)"cursorShape": "bar",// oh-my-posh 主题原因,使用其他的字体可能会出现乱码"fontFace": "Cascadia Code PL","fontSize": 12,// 透明度"acrylicOpacity": 0.90000000000000002,"useAcrylic": true},// 下拉快捷菜单 list// guid 唯一id 切记不要重复//是否隐藏 hidden// name 下拉菜单中展示的名字// tabTitle tab标签中 展示的名字// commandline 要加载的终端或命令// startingDirectory 默认目录 不填则打开用户目录,// icon 图标// historySize历史记录大小"list": [{"commandline": "powershell.exe","guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",//是否隐藏"hidden": false,"name": "Windows PowerShell",//"backgroundImage": "D:\\1.jpg", //背景图片路径//"backgroundImageOpacity": 0.05, //背景图片的透明度/* 背景图像填充方式 * none -> 显示原始大小,会留白* fill -> 充满,图像完整显示 会变形* uniform -> 图像放到最大,不变形会留白* uniformToFill -> 图像不变形,当道最大 并填充所有空白*/"backgroundImageStretchMode": "uniformToFill",},{"commandline": "cmd.exe","guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}","hidden": false,"name": "\u547d\u4ee4\u63d0\u793a\u7b26"},{"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}","hidden": false,"name": "PowerShell","source": "Windows.Terminal.PowershellCore"},{"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}","hidden": false,"name": "Azure Cloud Shell","source": "Windows.Terminal.Azure"}]},// 配色方案"schemes": [{"name": "Andromeda","black": "#000000","red": "#cd3131","green": "#05bc79","yellow": "#09da0f",// "yellow": "#e5e512","blue": "#2472c8","purple": "#bc3fbc","cyan": "#0fa8cd","white": "#e5e5e5","brightBlack": "#666666","brightRed": "#cd3131","brightGreen": "#05bc79","brightYellow": "#09da0f",// "brightYellow": "#e5e512","brightBlue": "#2472c8","brightPurple": "#bc3fbc","brightCyan": "#0fa8cd","brightWhite": "#e5e5e5","background": "#262a33","foreground": "#e5e5e5"},{"name": "Campbell","foreground": "#F2F2F2","background": "#0C0C0C","colors": ["#0C0C0C","#C50F1F","#13A10E","#C19C00","#0037DA","#881798","#3A96DD","#CCCCCC","#767676","#E74856","#16C60C","#F9F1A5","#3B78FF","#B4009E","#61D6D6","#F2F2F2"]},{"name": "Solarized Dark","foreground": "#FDF6E3","background": "#073642","colors": ["#073642","#D30102","#859900","#B58900","#268BD2","#D33682","#2AA198","#EEE8D5","#002B36","#CB4B16","#586E75","#657B83","#839496","#6C71C4","#93A1A1","#FDF6E3"]}],// 快捷键设置"actions": [{"command": {"action": "copy","singleLine": false},"keys": "ctrl+c"},{"command": "paste","keys": "ctrl+v"},// Press Ctrl+Shift+F to open the search box{"command": "find","keys": "ctrl+shift+f"},{"command": {"action": "splitPane","split": "auto","splitMode": "duplicate"},//alt+shift+d 分割窗口"keys": "alt+shift+d"}],}

配置项参考链接:Windows Terminal完整指南

美化好的终端配置推荐:点击查看效果和下载

其他参考链接: Dev on Windows with WSL

如果觉得《告别黑白CMD PowerShell + Windows Terminal 终端美化》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。