diff --git a/src/history.rs b/src/history.rs index 0b907d5..00b9933 100644 --- a/src/history.rs +++ b/src/history.rs @@ -16,6 +16,8 @@ pub enum HistoryProvider { Atuin, #[strum(serialize = "fish")] Fish, + #[strum(serialize = "nu")] + Nu, } impl HistoryProvider { @@ -52,6 +54,14 @@ impl HistoryProvider { .output()?; Ok(Box::new(Cursor::new(output.stdout))) } + HistoryProvider::Nu => { + let output = Command::new("nu") + .arg("-l") + .arg("-c") + .arg("history | default [] | each {|i| $\"($i.start_timestamp);($i.command)\"} | table --flatten -i false --theme none") + .output()?; + Ok(Box::new(Cursor::new(output.stdout))) + } } } } @@ -75,7 +85,10 @@ impl Iterator for History { fn next(&mut self) -> Option { match self.provider { - HistoryProvider::Zsh | HistoryProvider::Atuin | HistoryProvider::Fish => { + HistoryProvider::Zsh + | HistoryProvider::Atuin + | HistoryProvider::Nu + | HistoryProvider::Fish => { let mut block = String::new(); let mut buf = vec![]; loop { diff --git a/src/parser.rs b/src/parser.rs index 09348df..50fb333 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -72,6 +72,7 @@ impl CommandParser { HistoryProvider::Bash => self.parse_bash_raw(), HistoryProvider::Atuin => self.parse_atuin_raw(), HistoryProvider::Fish => self.parse_fish_raw(), + HistoryProvider::Nu => self.parse_nu_raw(), }?; let commands_splitted = RE_COMMAND.split(&commands_combined); for commandline in commands_splitted { @@ -115,17 +116,30 @@ impl CommandParser { )) } + pub fn parse_nu_raw(&self) -> Result> { + let (time_raw, commands_raw) = self + .raw + .split_once(';') + .ok_or("failed to split nu command")?; + + let time = NaiveDateTime::parse_and_remainder(time_raw.trim(), "%Y-%m-%d %H:%M:%S") + .ok() + .and_then(|naive_time| Local.from_local_datetime(&naive_time.0).single()); + + Ok((commands_raw.trim().into(), time)) + } + pub fn parse_atuin_raw(&self) -> Result> { let (time_raw, commands_raw) = self .raw .split_once(';') .ok_or("failed to split atuin command")?; - let time = NaiveDateTime::parse_from_str(time_raw, "%Y-%m-%d %H:%M:%S") + let time = NaiveDateTime::parse_from_str(time_raw.trim(), "%Y-%m-%d %H:%M:%S") .ok() .and_then(|naive_time| Local.from_local_datetime(&naive_time).single()); - Ok((commands_raw.into(), time)) + Ok((commands_raw.trim().into(), time)) } pub fn parse_fish_raw(&self) -> Result> {