Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ cmd-wrapped 2024
cmd-wrapped -s <shell>
```

对 `<shell>` 支持的选项:`zsh`、`bash`、`fish`、`atuin`。
对 `<shell>` 支持的选项:`zsh`、`bash`、`fish`、`nu`(`nushell`)、`xonsh`、`atuin`。

> [!NOTE]
>
> 在某些情况下,cmd-wrapped 可能无法输出正确的数据(例如 [所有输出均为 0](https://github.com/YiNNx/cmd-wrapped/issues/3))。这是因为它依赖于每个命令的时间戳记录,有时需要额外配置特定选项:
>
> - 对于 Zsh - [EXTENDED_HISTORY](https://zsh.sourceforge.io/Doc/Release/Options.html#History)(oh-my-zsh 默认启用)
> - 对于 Bash - [HISTTIMEFORMAT](https://www.gnu.org/software/bash/manual/bash.html#index-HISTTIMEFORMAT)
> - 对于 Nushell - 启用 SQLite 历史记录存储:`$env.config.history.file_format = "sqlite"`
>
> **在配置选项之前执行的命令将不会记录时间戳,这将影响 cmd-wrapped 的统计数据**。

## 致谢与许可证

- 特别感谢 [@jyi2ya](https://github.com/jyi2ya) 的绝妙想法!
- 许可证:[MIT](https://github.com/YiNNx/cmd-wrapped/blob/master/LICENSE)
- 许可证:[MIT](https://github.com/YiNNx/cmd-wrapped/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cmd-wrapped 2024
cmd-wrapped -s <shell>
```

Supported options for `<shell>` : `zsh`, `bash`, `fish`, `nu` (nushell), `atuin`.
Supported options for `<shell>` : `zsh`, `bash`, `fish`, `nu` (nushell), `xonsh`, `atuin`.

> [!NOTE]
>
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Cli {
)
.arg(
arg!(
-s --shell <SHELL> "Specify the target shell / history tool.\nSupported options - zsh, bash, fish, atuin"
-s --shell <SHELL> "Specify the target shell / history tool.\nSupported options - zsh, bash, fish, nu (nushell), xonsh, atuin"
)
.required(false),
)
Expand Down
12 changes: 12 additions & 0 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum HistoryProvider {
Fish,
#[strum(serialize = "nu")]
Nu,
#[strum(serialize = "xonsh")]
Xonsh,
}

impl HistoryProvider {
Expand Down Expand Up @@ -62,6 +64,15 @@ impl HistoryProvider {
.output()?;
Ok(Box::new(Cursor::new(output.stdout)))
}
HistoryProvider::Xonsh => {
let output = Command::new("xonsh")
.arg("-i")
.arg("-c")
.arg("history show all -t")
.env("XONSH_DATETIME_FORMAT", "%Y-%m-%d %H:%M:%S")
.output()?;
Ok(Box::new(Cursor::new(output.stdout)))
}
}
}
}
Expand All @@ -88,6 +99,7 @@ impl Iterator for History {
HistoryProvider::Zsh
| HistoryProvider::Atuin
| HistoryProvider::Nu
| HistoryProvider::Xonsh
| HistoryProvider::Fish => {
let mut block = String::new();
let mut buf = vec![];
Expand Down
13 changes: 13 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl CommandParser {
HistoryProvider::Atuin => self.parse_atuin_raw(),
HistoryProvider::Fish => self.parse_fish_raw(),
HistoryProvider::Nu => self.parse_nu_raw(),
HistoryProvider::Xonsh => self.parse_xonsh_raw(),
}?;
let commands_splitted = RE_COMMAND.split(&commands_combined);
for commandline in commands_splitted {
Expand Down Expand Up @@ -154,6 +155,18 @@ impl CommandParser {
Ok((commands_raw.into(), time))
}

pub fn parse_xonsh_raw(&self) -> Result<ParsingData, Box<dyn Error>> {
let (time_raw, commands_raw) = self
.raw
.split_once(") ")
.ok_or("failed to split xonsh command")?;

let time = NaiveDateTime::parse_from_str(time_raw[1..].trim(), "%Y-%m-%d %H:%M:%S")
.ok()
.and_then(|naive_time| Local.from_local_datetime(&naive_time).single());
Ok((commands_raw.into(), time))
}

pub fn finish(self) -> Vec<Command> {
self.commands
}
Expand Down