一小股火星军, 两小股火星军, 三小股火星军~

终端环境配置 (oh-my-zsh)

2021-08-26

这篇文章记录我对开发环境: 终端的配置. 主要是 oh-my-zsh (for *nix) 和 oh-my-posh (for Windows).

目录

oh-my-zsh

oh-my-zsh 安装

oh-my-zsh 算是 zsh 的一个配置管理工具, 有很多终端主题或者工具是基于它开发的.

  1. 安装 zsh
    $ sudo apt install zsh
  2. 安装 oh-my-zsh
    $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  3. 更改你的默认 shell
    chsh -s /bin/zsh

主题安装

接下来就可以安装好看的主题了, 这里以 powerlevel10k 为例:

  1. 安装对应字体, p10k 有很多特殊字符, 需要 Nerd Font 对现有字体进行处理插入符号 (比较复杂). 也可以在它的官网下载预处理好的字体. 这里推荐 JetBrainMono Nerd Font, 它是基于 JetBrain 官方字体插入符号得到的. 下载下来是一个 zip 压缩包, 解压后找到

    • JetBrains Mono Bold Italic Nerd Font Complete.ttf
    • JetBrains Mono Bold Nerd Font Complete.ttf
    • JetBrains Mono Italic Nerd Font Complete.ttf
    • JetBrains Mono Regular Nerd Font Complete.ttf

    这四个字体进行安装. Windows 和 MacOS 字体安装过程都很简单, Linux 稍微复杂些.

    1
    2
    3
    4
    5
    $ mkdir /usr/share/fonts/jetfonts
    $ cd /usr/share/fonts/jetfonts
    $ mkfontscale
    $ mkfontdir
    $ fc-cache -fv
  2. 设置刚才安装的字体

    • vscode 下在配置文件中增加
      1
      2
      "editor.fontFamily": "JetBrainsMono Nerd Font, 'Courier New', monospace",
      "editor.fontLigatures": true
    • Windows Terminal 在配置文件中, default 项下增加
      1
      "fontFace": "JetBrainsMono Nerd Font",
  3. 安装 p10k

    1
    2
    $ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
    $ echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
  4. 配置p10k, p10k 提供了自动配置指南, 运行 p10k configure 即可. 或者从之前的~/.p10k.zsh中恢复.

插件安装

oh-my-zsh 还有许多功能强大的小插件, 像是命令补全和命令高亮等.

  1. 安装命令补全
    1
    $ git clone https://github.com.cnpmjs.org/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  2. 安装命令高亮
    1
    $ git clone https://github.com.cnpmjs.org/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

执行以上命令后在~/.zshrc中修改添加

1
2
3
4
5
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)

oh-my-posh

oh-my-posh 是 Windows 下类似 oh-my-zsh 的 powershell 插件. (但是装好以后启动powershell变得特别慢...)
  1. 安装 oh-my-posh 和 posh-git
    1
    2
    $ Install-Module -Name oh-my-posh -Scope CurrentUser
    $ Install-Module posh-git -Scope CurrentUser
  2. 配置 powershell 加载配置 $ code $PROFILE
    1
    2
    3
    Import-Module posh-git
    Import-Module oh-my-posh
    Set-PoshPrompt -Theme iterm2

终端配色设置

配置颜色为 Dracula.

Windows Terminal

在 Windows Terminal设置中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"profiles": {
"defaults": {
"colorScheme" : "Dracula"
}
}

"schemes": [
{
"name": "Dracula",
"cursorColor": "#F8F8F2",
"selectionBackground": "#44475A",
"background": "#282A36",
"foreground": "#F8F8F2",
"black": "#21222C",
"blue": "#BD93F9",
"cyan": "#8BE9FD",
"green": "#50FA7B",
"purple": "#FF79C6",
"red": "#FF5555",
"white": "#F8F8F2",
"yellow": "#F1FA8C",
"brightBlack": "#6272A4",
"brightBlue": "#D6ACFF",
"brightCyan": "#A4FFFF",
"brightGreen": "#69FF94",
"brightPurple": "#FF92DF",
"brightRed": "#FF6E6E",
"brightWhite": "#FFFFFF",
"brightYellow": "#FFFFA5"
}
]