Files
dotfiles/memo/kmscon.md
2025-12-18 17:27:37 +01:00

98 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> 鬼知道这有什么意义,但是在 tty 里用 monospace 和 cjk 字体真的很酷
## 安装
AUR - `kmscon`
## 在所有 VT (虚拟终端) 上启用
```bash
sudo ln -s '/usr/lib/systemd/system/kmsconvt@.service' '/etc/systemd/system/autovt@.service'
```
以及保留 tty1 给 getty 使用:
```bash
sudo systemctl enable getty@tty1.service
```
理由:
1. kmscon 中通过命令行启动图形 session 会遇到问题。
2. 通常 tty1 用于运行图形界面,不需要 kmscon 提供的各种特性。
## 修改默认配置
```bash
sudo systemctl edit autovt@.service
```
然后添加以下内容:
```ini
[Service]
ExecStart=
ExecStart=/usr/bin/kmscon --vt=%I --seats=seat0 --no-switchvt
```
解释:
1. 默认的 `ExecStart` 携带的单数会覆盖所有配置文件,需要先清空。
2. 保留默认参数 `--login` 前的部分,因为我看不出不这么做的理由。
然后就可以在 `/etc/kmscon/kmscon.conf` 添加自定义的配置了。
例如:
```conf
login=/bin/login -p -f kolkas
font-name=MesloLGM Nerd Font Mono, Maple Mono NF CN
font-size=14
```
其中:
- `login=/bin/login -p -f kolkas` 指定自动登录用户。
- `font-name``font-size` 用于设置字体和大小。
## 关于字体的补充说明
1. kmscon 上 2 字符宽的 nerd font 图标会被裁剪至 1 字符宽。因此我使用 MesloLGM Nerd Font Mono 作为首选字体,它的图标字符只有 1 字符宽。
2. [Archwiki - KMSCON](https://wiki.archlinux.org/title/KMSCON) 上提供了另一种更改字体的方法,即修改 fontconfig 配置,具体做法为在 monospace 字体族中前置添加字体。但这会影响所有使用 fontconfig 和 monospace 字体族的程序,包括图形界面中的终端模拟器。因此我选择直接在 kmscon 的配置文件中指定字体。
## 检测当前终端是否为 kmscon
> 以下代码片段适用于 fish shell
检测父进程和祖父进程是否为 kmscon
```sh
if ps -e -o pid,comm | grep -q (pgrep kmscon)
# 在 kmscon 中
end
```
或者更精细地检测所有祖先进程 (fish)
```sh
function is_kmscon
set -l pid %self
while test $pid -gt 1
set -l info (ps -o ppid=,comm= -p $pid | string trim)
set -l ppid (echo $info | awk '{print $1}')
set -l name (echo $info | awk '{print $2}')
if string match -q "kmscon" $name
return 0
end
set pid $ppid
end
return 1
end
if is_kmscon
# 在 kmscon 中
end
```