diff --git a/README-CN.md b/README-CN.md index 174e84b..db16b2e 100644 --- a/README-CN.md +++ b/README-CN.md @@ -50,7 +50,7 @@ cmd-wrapped 2024 cmd-wrapped -s ``` -对 `` 支持的选项:`zsh`、`bash`、`fish`、`atuin`。 +对 `` 支持的选项:`zsh`、`bash`、`fish`、`nu`(`nushell`)、`xonsh`、`atuin`。 > [!NOTE] > @@ -58,10 +58,11 @@ cmd-wrapped -s > > - 对于 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) \ No newline at end of file +- 许可证:[MIT](https://github.com/YiNNx/cmd-wrapped/blob/master/LICENSE) diff --git a/README.md b/README.md index fa11394..3702a8b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ cmd-wrapped 2024 cmd-wrapped -s ``` -Supported options for `` : `zsh`, `bash`, `fish`, `nu` (nushell), `atuin`. +Supported options for `` : `zsh`, `bash`, `fish`, `nu` (nushell), `xonsh`, `atuin`. > [!NOTE] > diff --git a/src/cli.rs b/src/cli.rs index 8209da1..c4ac5ce 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -26,7 +26,7 @@ impl Cli { ) .arg( arg!( - -s --shell "Specify the target shell / history tool.\nSupported options - zsh, bash, fish, atuin" + -s --shell "Specify the target shell / history tool.\nSupported options - zsh, bash, fish, nu (nushell), xonsh, atuin" ) .required(false), ) diff --git a/src/history.rs b/src/history.rs index f4b789d..d247e32 100644 --- a/src/history.rs +++ b/src/history.rs @@ -18,6 +18,8 @@ pub enum HistoryProvider { Fish, #[strum(serialize = "nu")] Nu, + #[strum(serialize = "xonsh")] + Xonsh, } impl HistoryProvider { @@ -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))) + } } } } @@ -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![]; diff --git a/src/parser.rs b/src/parser.rs index bbea647..424f393 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 { @@ -154,6 +155,18 @@ impl CommandParser { Ok((commands_raw.into(), time)) } + pub fn parse_xonsh_raw(&self) -> Result> { + 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 { self.commands }