Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🚧 experimental but funcional nushell support #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 14 additions & 1 deletion src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum HistoryProvider {
Atuin,
#[strum(serialize = "fish")]
Fish,
#[strum(serialize = "nu")]
Nu,
}

impl HistoryProvider {
Expand Down Expand Up @@ -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)))
}
}
}
}
Expand All @@ -75,7 +85,10 @@ impl Iterator for History {

fn next(&mut self) -> Option<Self::Item> {
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 {
Expand Down
18 changes: 16 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -115,17 +116,30 @@ impl CommandParser {
))
}

pub fn parse_nu_raw(&self) -> Result<ParsingData, Box<dyn Error>> {
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<ParsingData, Box<dyn Error>> {
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<ParsingData, Box<dyn Error>> {
Expand Down