9 个版本
0.2.10 | 2024 年 7 月 29 日 |
---|---|
0.2.9 | 2024 年 7 月 28 日 |
0.2.7 | 2023 年 11 月 11 日 |
0.2.6 | 2023 年 10 月 25 日 |
0.2.2 | 2022 年 9 月 5 日 |
#247 在 Unix API 中
每月 444 次下载
25KB
309 行
捕捞
简单 XRcources 风格的基于 Linux 的配置系统,独立于发行版/显示后端(Wayland / X11 等)。
构建说明
请确保您已安装 Rust 工具链(版本 >= 1.62)。使用以下命令构建所有二进制文件
git clone https://github.com/regolith-linux/trawl.git
cd trawl
make
注意 1:将 cargo build
替换为 cargo build --release
以在发布模式下构建二进制文件。
注意 2:二进制文件位于 target/debug
目录(如果以发布模式构建,则为 target/release
)。
注意 3:第一次运行 make setup
命令时会失败。这是因为在此步骤中生成了 dbus-interface 的代码。您可以忽略此错误,并继续执行以下命令。
安装说明
git clone https://github.com/regolith-linux/trawl.git
cd trawl
# enable the "install" target in the Makefile
make install
systemctl daemon-reload
systemctl enable --now trawld
注意:第一次运行 make setup
命令时会失败。这是因为在此步骤中生成了 dbus-interface 的代码。您可以忽略此错误,并继续执行以下命令。
特性
- XRcources 类型的基于文件的配置系统。
- 与现有的
XRcources
文件兼容。 - 与显示后端和发行版无关。
- 轻量级且 简单易用。
- 使用 DBus 会话总线 来建立 IPC。这允许每个用户运行他们自己的配置管理器实例。
用法
在二进制文件前加上构建目录的路径(target/debug
或 target/release
)即可使用,无需安装。
资源文件 / 配置文件格式
- 资源文件中的每一行都是一个以 ':' 分隔的键值对。例如:
key1: value1 key2: value2
- 有效的键是一个没有空白的 ASCII 字符串,但可以包括以下特殊字符 -- ' - ', ' . ', ' _ '。例如:
sway-wm.screen_timeout: 100
- 如果一行包含多个冒号(':'),则第一个冒号之前的内容被视为键,第一个冒号之后的内容被视为值。例如:
swaywm.workspace.1.name: 1: Shell
- 值可以是任何 UTF-8 字符串。
- 注释以 '//' 开头,将被忽略。
- 默认情况下,预处理指令(以 '#' 开头)由 c 预处理器处理。如果指令不被识别,则忽略。
- 预处理指令可以用来包含其他文件。指令的形式为
#include <file>
。文件相对于资源文件。#include <config.d/swayidle>
- 预处理指令可以用来定义宏。指令的形式为
#define <macro> <value>
。宏是一个字符串,值也是一个字符串。宏在资源文件中定义。#define USERNAME "John Doe"
- 就像在 C 中一样,可以使用
#ifdef
和ifndef
指令有条件地忽略 / 包含资源文件的某些部分。#ifdef USERNAME swaylock.greeter.user USERNAME // USERNAME is replaced with John Doe #endif
启动配置管理器(trawld)
运行 trawld
以启动配置守护进程。您可以将可选参数传递给守护进程以自定义行为或更改日志级别。运行 trawld --help
获取更多信息。
使用 CLI 客户端(trawldb)
CLI 客户端允许用户与配置管理器交互。客户端的主要功能包括从文件中加载配置。运行 trawldb --help
获取更多信息。
示例
- 加载文件
# load a file (doesn't overwrite existing resources) trawldb --load example/resources # load a file without preprocessing resrdb --load example/resources --nocpp
- 合并来自文件的资源
# merge resource from a file (overrides existing resources) trawldb --merge example/resources # merge resource from a file without preprocessing trawldb --merge example/resources --nocpp
- 将当前加载的资源保存到文件中
# if file exists it is backed up to a file with the same name but with a .bak extension trawldb --edit all_resources # specify suffix for -edit [.bak] trawldb --edit all_resources --backup .old
- 查询资源
# query all resources trawldb --query # query a specific resource (partial matches are also shown) trawldb --query key1
- 获取资源值
# get the value for the resouource whose name is 'key1' trawldb --get key1
获取资源值(trawlcat)
trawlcat
是 xrescat
的直接替代品,并打印请求的资源值。有关更多信息,请参阅 (xrerscat) 文档。
C 客户端 API(用于 C)
DBus 接口的头文件和实现文件在 service.xml
文件在 meson
构建期间自动生成。头文件 client_api.h
提供了一个简单的包装 API。所有 dbus 方法名称都是蛇形命名,并以前缀 conf_client
开头。
Rust 客户端库
在 Cargo.toml
文件中包含 trawldb
包。然后您可以使用 Rust 客户端库与配置管理器交互。
[dependencies]
trawldb = { path = "/path/to/trawldb" }
依赖关系
~10–21MB
~300K SLoC