let reader = std::io::BufReader::new(histfile);
let mut acc_time_finished: Option<DateTime<Utc>> = None;
let mut acc_result: Option<usize> = None;
let mut acc_command: Option<String> = None;
let mut multiline_command = false;
let mut entries = Vec::new();
for line in reader.lines() {
let line = match line {
Err(err) => {
warn!("{}", err);
continue;
}
Ok(line) => line,
};
// End of multiline command
if line.starts_with(':') && multiline_command {
let time_finished = acc_time_finished.unwrap();
let result = acc_result.unwrap();
let command = acc_command.unwrap();
acc_time_finished = None;
acc_result = None;
acc_command = None;
multiline_command = false;
entries.push(HistfileEntry {
time_finished,
result,
command,
})
}
if line.starts_with(':') {
let mut split = line.split(':');
let timestamp = split.nth(1).unwrap().trim();
let code_command = split.collect::<Vec<_>>().join(":");
let mut code_command = code_command.split(';');
let code = code_command.next().unwrap();
let command = code_command.collect::<Vec<_>>().join(";");
let time_finished = chrono::DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp(timestamp.parse().unwrap(), 0),
Utc,
);
let result = code.parse().unwrap();
if command.ends_with('\\') {
acc_time_finished = Some(time_finished);
acc_result = Some(result);
acc_command = Some(format!("{}\n", command.trim_end_matches('\\')));
multiline_command = true;
} else {
entries.push(HistfileEntry {
time_finished,
result: code.parse().unwrap(),
command,
})
}
} else if let Some(ref mut acc) = acc_command {
acc.push_str(&line);
acc.push('\n');
} else {
panic!("line not starting with : and no multiline command")
}
}
if acc_command.is_some() {
let time_finished = dbg!(acc_time_finished).unwrap();
let result = dbg!(acc_result).unwrap();
let command = dbg!(acc_command).unwrap();
entries.push(HistfileEntry {
time_finished,
result,
command,
})
}
let store = crate::store::new(data_dir);
let hostname = hostname::get()
.map_err(Error::GetHostname)?
.to_string_lossy()
.to_string();
let base_dirs = directories::BaseDirs::new().unwrap();
let pwd = base_dirs.home_dir().to_path_buf();
let user = std::env::var("USER").unwrap();
let session_id = Uuid::new_v4();
for histfile_entry in entries {
let time_finished = histfile_entry.time_finished;
let time_start = histfile_entry.time_finished;
let result = histfile_entry.result;
let command = histfile_entry.command;
let hostname = hostname.clone();
let pwd = pwd.clone();
let user = user.clone();