fix: make statusline work cleanly on Linux too

- install: only convert backslashes to slashes on Windows (backslash is a valid char in Unix paths)
- config dir resolution already falls back from USERPROFILE to HOME, covering both platforms
- README: cross-platform build/install instructions, recommend the install command
This commit is contained in:
2026-06-25 19:13:47 +08:00
Unverified
parent 95e3ddbd9c
commit 394c828ace
2 changed files with 28 additions and 4 deletions
+19 -2
View File
@@ -11,15 +11,32 @@
| 速度 | `↑ 1.2k ↓ 134.4 t/s` | 最近 8 次请求的输入/输出 token 速度 |
| 额度 | `10% - 40% · 1:45` | 5h 已用 - 7 天已用 · 5h 刷新倒计时(越近越红) |
## 构建
```bash
cargo build --release
# 产物:Linux/macOS 为 target/release/statuslineWindows 为 target/release/statusline.exe
```
## 接入 Claude Code
编辑 `~/.claude/settings.json``statusLine.command` 指向构建产物(用正斜杠路径):
推荐用内置 `install` 命令,自动定位配置目录、`statusLine.command` 指向当前可执行文件(跨平台,含空格的路径自动加引号):
```bash
./target/release/statusline install # 用户级:CLAUDE_CONFIG_DIR 或 ~/.claude
./target/release/statusline install project # 项目级:./.claude/settings.json
./target/release/statusline install local # 项目本地:./.claude/settings.local.json
```
或手动编辑 `settings.json`(路径含空格时用引号包裹):
```json
{
"statusLine": {
"type": "command",
"command": "statusline"
"command": "/abs/path/to/statusline"
}
}
```
> 需要倒计时/速度持续刷新,可加 `"refreshInterval": 10`(单位秒)。
+9 -2
View File
@@ -85,10 +85,17 @@ fn settings_path(scope: Option<&str>) -> Option<PathBuf> {
}
}
/// 当前可执行文件的绝对路径,反斜杠转正斜杠(bash 调用时更稳)
/// 当前可执行文件的绝对路径。
/// Windows 下把反斜杠转成正斜杠(bash 调用更稳);其它平台原样保留
/// (类 Unix 路径里反斜杠是合法字符,不能替换)。
fn current_exe_path() -> Option<String> {
let p = std::env::current_exe().ok()?;
Some(p.to_string_lossy().replace('\\', "/"))
let s = p.to_string_lossy().into_owned();
if cfg!(windows) {
Some(s.replace('\\', "/"))
} else {
Some(s)
}
}
/// Claude 用户级配置目录:优先 `CLAUDE_CONFIG_DIR`,否则 `~/.claude`。