End

Terminal 终端 oh-my-posh 主题

本文地址


目录

Windows Terminal

Terminal 简介

Windows Terminal 是一个面向命令行工具shell(如命令提示符、PowerShell 和 WSL)用户的新式终端应用程序

Windows Terminal 是 WSL2 的理想配套,它速度快、可配置、外观漂亮,并且提供了 Windows 和 Linux 开发的所有优点。

主要特性

  • 多个选项卡拆分窗格
  • 支持多种命令行应用程序:WSL2,SSH,Powershell,cmd和其他命令行
  • 完全自定义:自定义操作,自定义快捷键,自定义主题、样式、配置
  • 美观的新字体 Cascadia Code,支持背景图像支持
  • 完全 Unicode、UTF-8 字符支持,如各种语言的表情符号和字符
  • 支持命令行参数:在特定配置中启动,如启动目录、启动配置、专注的选项卡
  • 免费开源,Microsoft 一贯的良好文档(全中文)
  • 高性能:GPU 加速文本渲染引擎,资源使用率低,每个选项卡通常10MB
  • 搜索框

缺点:

  • 完全通过 json 配置,自定义成本较高
  • 无桌面快捷方式:可以锁定到开始锁定到任务栏

使用技巧

  • 按住 Ctrl 并滚动鼠标滚轮调整活动终端的文本大小
  • 支持选择时自动复制(需要自定义设置),右键单击鼠标粘贴
  • 在标签上点击中键,或输入终端的标准退出命令exit,可以关闭当前标签
  • 单击 + 图标或 Ctrl + Shift + T 打开默认配置文件的新标签
  • 快捷键 Alt + Shift + D 可复制并沿最长轴拆分窗格
  • 从下拉菜单中选择时按住 Alt 键,可以在新拆分窗格中打开另一个配置文件
  • Ctrl + Shift + F 打开搜索框

添加 Bash 到 Terminal

  • 在 Terminal 上方标签栏点击下拉按钮找到设置并点击,然后将会打开settings.json,这个就是 Terminal 的配置文件。
  • 在配置 profiles 下的 list 中添加 Bash 的配置,保存后重启。
  • 更多详细设置,详见官方文档 customize-settings/profiles
{
    "commandline": "C:\\_dev\\_Tools\\Git\\bin\\bash.exe -li",
    "startingDirectory" : "C:/Users/白乾涛/Desktop",
    "icon" : "C:/_dev/_Tools/Git/mingw64/share/git/git-for-windows.ico",
    "guid": "{1cb09cbb-0365-91bf-c98f-d8d03c510274}",
    "hidden": false,
    "name": "Bash"
}
  • guid:唯一标识本命令行配置,可以使用 在线guid工具 随机生成一个
  • commandline:是 git 安装目录下的 bin 目录下的bash.exe,不是 git 安装目录下的git-bash.exe,路径分隔符可以用\\/
  • startingDirectory:启动目录

oh-my-posh

A prompt theme engine for any shell.

Oh My Posh is a custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable.

Oh-My-Posh 是一款命令行提示主题引擎,其受启发于 MacOS/Linux 上广泛使用的 Oh-My-Zsh

特点

  • Colors:Oh My Posh enables you to use the full color set of your terminal by using colors to define and render the prompt 呈现提示.
  • Customizable 可定制:Easily adjust 调整 existing themes or create your own. From standard segments(片段) all the way to custom implementations.
  • Portable 便携:No matter which shell you're using, or even how many, you can carry the configuration from one shell and/or machine to another for the same prompt everywhere you work.

Features

  • Shell independent
  • Git status indications 状态指示
  • Failed command indication 失败指令指示
  • Admin indication 管理员指示
  • Current session indications 当前会话指示
  • Language info
  • Shell info
  • Configurable

安装

下面的命令请在Windows Terminal中以管理员身份运行执行。

Set-ExecutionPolicy Bypass                    # 绕过执行策略,使其可以执行脚本文件
Install-Module oh-my-posh -Scope CurrentUser  # 以管理员身份安装,如果有询问,直接Y就好了
Update-Module oh-my-posh                      # 更新

oh-my-posh -version                           # 查看版本
oh-my-posh -print-shell                       # 查看当前使用的是哪个 shell

主题配置

Get-PoshThemes           # 预览本地所有主题
Get-PoshThemes -list     # 打印本地所有主题及其路径
echo $PROFILE            # 打印配置文件路径(C:\Users\白乾涛\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1)
echo $HOME               # 打印当前用户路径(C:\Users\白乾涛)
notepad $PROFILE         # 使用记事本打开配置文件

1、对于 PowerShell,在配置文件$PROFILE中写入如下内容即可设置主题为JanDeDobbeleer,注意重启才会生效。

Set-PoshPrompt -Theme JanDeDobbeleer

2、对于 Terminal 中的 Git Bash

  • 将主题文件拷贝到$HOME目录(即C:\Users\白乾涛)下
  • $HOME目录下创建.profile文件,并添加以下命令,注意重启才会生效。
eval "$(oh-my-posh --init --shell bash --config ~/jandedobbeleer.omp.json)"

设置字体

设置主题并重启后,你会发现出现了一些方框,效果并不像图片上那么好,那是因为没有给主题安装适应的字体。

  • 进入上面的网站,点击Downloads,随便下载一款字体,例如 DejaVuSansMono Nerd FontCousine Nerd Font,下载完成后,解压到当前文件夹,然后CTRL+A全选,右键点击安装,等待安装完成即可。
  • 在 Terminal 上方标签栏点击下拉按钮找到设置并点击,然后将会打开settings.json,这个就是 Terminal 的配置文件。
  • 在配置 profiles 中找到 PowerShell,将其中键为fontFace的值对改为刚刚下载的字体名称,保存后重启。
{
    "commandline": "powershell.exe",
    "fontFace": "Cousine Nerd Font",
    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "hidden": false,
    "name": "Windows PowerShell"
}

修改 IDEA 中的 Terminal

  • 修改默认终端:File | Settings | Tools | Terminal
    • cmd:cmd.exe
    • powershell:powershell.exe
    • bash:C:/_dev/_Tools/Git/bin/bash.exe -li
  • 修改字体、字号:Editor-->Color Scheme-->Console Font
  • 修改颜色:Editor-->Color Scheme-->Console Font

2018-07-18

posted @ 2018-07-18 22:29  白乾涛  阅读(3377)  评论(0编辑  收藏  举报