﻿---
title: Personalization for Terminal，Shell & Prompt
date: 2024-10-19
excerpt: 工欲善其事必先利其器，终端算是编程中经常接触的“器”，下面记录个人针对terminal,shell和prompt的一些个性化设置，仅供参考
tags:
  - Terminal
  - Windows
  - Nushell
  - Productivity
  - Workflow
cover: https://assets.vluv.space/cover/Dev/Others/terminal.webp
---

<script data-swup-reload-script type="module" src="/js/components/tab.js"></script>

## 📚Related Glossary

|          | Meaning                                                  | Examples                                    |
| -------- | -------------------------------------------------------- | ------------------------------------------- |
| Terminal | A text input and output environment.                     | Windows Terminal，Alacritty，Kitty，Wezterm... |
| Console  | A physical terminal.                                     |                                             |
| Shell    | command-line interpreter                                 | nushell，bash，zsh，fish，powershell...         |
| Prompt   | The text that appears at the beginning of a command line | 形如`$`，`>>>`                                 |

## ⌨️Terminal

个人体验的终端有 Windows Terminal，Wezterm；

Wezterm 可自定义的程度比较高，可以自定义 tab 的位置&样式，但体验过程中，Wezterm 的启动速度相对较慢，目前主要使用 Windows Terminal

我的一些个性化设置

- 字体: [Maple Mono NF CN](https://github.com/subframe7536/maple-font)，对 Ligatures，中文支持比较好的 Nerd Font;
- toggle focus mode: 选择开启 Focus Mode，可以隐藏上方 tab 栏，让界面更简洁
- Color Schemes：Tokyo Night 或 Catppuccin Mocha；比较美观的两款夜间主题，你可以在[windowsterminalthemes.dev](https://windowsterminalthemes.dev)找到更多主题
- Appearance: 在 Transparency 中选择 Enable acrylic material，启用亚克力效果；透明度 80%

![showcase](https://assets.vluv.space/Dev/terminal/wt.webp)

## 🐚Shell

个人觉得比较好用的 shell 有 [Nushell](https://www.nushell.sh)，fish; Powershell 功能也很强大，但启动速度慢，对使用体验有些影响。

Nushell 社区比较活跃，e.g. [nu_scripts](https://github.com/nushell/nu_scripts) 仓库维护了社区用户分享的 nushell 配置，喜欢折腾的可以参考本仓库。

下面是个人的 Nushell Config，配置文件比较长，考虑篇幅，这里只附上关键内容。有需要完整配置的可以联系作者

### Keybindings

我下载了 fzf 以及 bat 这两个命令行工具，配合以下配置可以方便的检索历史命令以及文件；此外还有一些比较实用的命令行工具，放在文末

```nushell keybindings.nu
$env.config.keybindings = (
    $env.config.keybindings
    | append {  # history_menu using fzf
        name: fzf_history_menu_fzf_ui
        modifier: control
        keycode: char_r
        mode: [emacs， vi_normal， vi_insert]
        event: {
            send: executehostcommand
            cmd: "commandline edit --insert (cat $nu.history-path | fzf --height 70% --layout reverse --border +s --tac | str trim)"
        }
    }
    | append {
        name: fuzzy_file
        modifier: control
        keycode: char_t
        mode: emacs
        event: {
        send: executehostcommand
        cmd: "commandline edit --insert (fzf --layout=reverse --preview 'bat --color=always --style=numbers --line-range=:500 {}')"
        }
    }
)
# 在你的config.nu里
source <path_to_keybind.nu>
```

<x-tabs>

<x-tab title="history" active>

![](https://assets.vluv.space/Dev/terminal/2024-10-19_15-43-39.gif)

</x-tab>

<x-tab title="fuzzy_file">

![](https://assets.vluv.space/Dev/terminal/2024-10-19_15-35-59.gif)

</x-tab>

</x-tabs>

### Completions

[nu_scripts](https://github.com/nushell/nu_scripts) 仓库中提供了部分命令的补全脚本，如 `docker` ，`git` 等，下载后放在某个目录下，然后在 `config.nu` 中引用补全脚本即可

此外，Nushell 支持使用 zoxide,carapace 等外部补全工具，可以不必依赖内置的补全脚本，个人相关配置详见[[nu_completion|这篇文章]]，Nushell Cook Book 中也有介绍 [External Completers](https://www.nushell.sh/cookbook/external_completers.html)

<x-tabs>

<x-tab title="ide-style" active>

![ide-style](https://assets.vluv.space/Dev/terminal/completions.webp)

</x-tab>

<x-tab title="list-style">

![list-style](https://assets.vluv.space/Dev/terminal/terminal-5.webp)

</x-tab>

</x-tabs>

---

## Prompt

Prompt 的美化方案有很多，比较知名的有 starship，ohmyzsh，ohmyposh; 这里采用 [ohmyposh](https://ohmyposh.dev)；

此前 omp 采用 Powershell 编写，后来为了兼容性用 go 重写，现在适用于 powershell，nushell，fish，zsh，bash 等等，甚至在安卓上也可以食用；

oh my posh 对自定义的支持程度非常高，支持的 Prompt 内容也很广泛，包括但不限于

- OS
- docker
- git
- java、python、golang、rust...
- path
- Execution Time

添加一些 prompt 对开发体验有一定提升。我在官方提供的主题上进行了自定义，配置文件放在后面仅供参考

显示效果如下图所示，配置文件见 [dotfiles/tui_cli/ohmyposh/omp.json at main · Efterklang/dotfiles](https://github.com/Efterklang/dotfiles/blob/main/tui_cli/ohmyposh/omp.json)

![prompt](https://assets.vluv.space/Dev/terminal/nushell.webp)

## 🛠️CLI & TUI

下面是一些比较实用/有意思的命令行工具

### TUI

- [gitui](https://github.com/extrawurst/gitui)
  Blazing 💥 fast terminal-ui for git written in rust 🦀
  类似于 lazygit，在终端中管理 git repo，适合不想动鼠标的人
  <img src="https://assets.vluv.space/Dev/terminal/terminal-3.webp" style="width:50%" />
- [btop](https://github.com/aristocratos/btop)
  A monitor of resources
  任务管理器 TUI 版，同样适合纯键盘操作
  <img src="https://assets.vluv.space/Dev/terminal/terminal-2.webp" style="width:50%" />
- [yazi](https://github.com/sxyazi/yazi)
  💥 Blazing fast terminal file manager written in Rust， based on async I/O.
  支持 windows 平台的 terminal file manager，除此之外 midnight commander 也支持 windows；适合纯键盘操作
  <img src="https://assets.vluv.space/Dev/terminal/terminal-4.webp" style="width:50%" />

### CLI

- [bat](https://github.com/sharkdp/bat)
  A cat clone with syntax highlighting and Git integration.
  相比 cat 多了语法高亮，可选择多种主题；
  <img src="https://assets.vluv.space/Dev/terminal/terminal-1.webp" style="width:50%" />
- [zoxide](https://github.com/ajeetdsouza/zoxide)
  A smarter cd command. Supports all major shells.
  快速切换目录

下面三个都是搜索类的工具，ripgrep 是 grep 的替代品(项目名意为 R.I.P grep)，VSCode 的快速搜索便是用的 ripgrep，fzf 可以与其它的工具相结合，用于模糊搜找文件，历史记录等等..

- [ripgrep](https://github.com/BurntSushi/ripgrep)
  ripgrep recursively searches directories for a regex pattern while respecting your gitignore
- [fd](https://github.com/sharkdp/fd)
  A simple， fast and user-friendly alternative to find.
- [fzf](https://github.com/junegunn/fzf)
  🌸 A command-line fuzzy finder;

MISC

- [fastfetch](https://github.com/fastfetch-cli/fastfetch)
- [curlie](https://github.com/rs/curlie)
  The power of curl， the ease of use of httpie.
- [gping](https://github.com/orf/gping)
  Ping， but with a graph
- code2prompt
- tokei
