2021-02-14 10:18:02 -07:00
|
|
|
#![feature(str_split_once)]
|
2021-02-14 06:28:01 -07:00
|
|
|
#![feature(proc_macro_hygiene)]
|
|
|
|
#![feature(decl_macro)]
|
2021-02-14 08:15:26 -07:00
|
|
|
#![warn(clippy::pedantic, clippy::nursery)]
|
2021-02-14 06:28:01 -07:00
|
|
|
|
2020-10-05 10:20:48 -06:00
|
|
|
use std::path::PathBuf;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2020-10-05 10:20:48 -06:00
|
|
|
use directories::ProjectDirs;
|
|
|
|
use eyre::{eyre, Result};
|
2020-10-05 04:52:03 -06:00
|
|
|
use structopt::StructOpt;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2020-10-05 10:20:48 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2021-02-14 06:28:01 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
|
2021-02-14 10:18:02 -07:00
|
|
|
use command::AtuinCmd;
|
2021-02-14 08:15:26 -07:00
|
|
|
use local::database::Sqlite;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2021-02-13 12:37:00 -07:00
|
|
|
mod command;
|
|
|
|
mod local;
|
2021-02-14 08:15:26 -07:00
|
|
|
mod remote;
|
2021-02-13 12:37:00 -07:00
|
|
|
|
2020-10-05 04:52:03 -06:00
|
|
|
#[derive(StructOpt)]
|
|
|
|
#[structopt(
|
2020-10-05 10:20:48 -06:00
|
|
|
author = "Ellie Huxtable <e@elm.sh>",
|
2021-02-15 16:33:30 -07:00
|
|
|
version = "0.3.2",
|
2021-02-14 15:33:22 -07:00
|
|
|
about = "Magical shell history"
|
2020-10-05 04:52:03 -06:00
|
|
|
)]
|
2021-02-13 05:58:40 -07:00
|
|
|
struct Atuin {
|
2020-10-05 10:34:28 -06:00
|
|
|
#[structopt(long, parse(from_os_str), help = "db file path")]
|
2020-10-05 10:20:48 -06:00
|
|
|
db: Option<PathBuf>,
|
|
|
|
|
|
|
|
#[structopt(subcommand)]
|
2021-02-13 05:58:40 -07:00
|
|
|
atuin: AtuinCmd,
|
2020-10-05 10:20:48 -06:00
|
|
|
}
|
|
|
|
|
2021-02-13 05:58:40 -07:00
|
|
|
impl Atuin {
|
2020-10-05 10:20:48 -06:00
|
|
|
fn run(self) -> Result<()> {
|
2021-02-14 08:15:26 -07:00
|
|
|
let db_path = if let Some(db_path) = self.db {
|
|
|
|
let path = db_path
|
|
|
|
.to_str()
|
|
|
|
.ok_or_else(|| eyre!("path {:?} was not valid UTF-8", db_path))?;
|
|
|
|
let path = shellexpand::full(path)?;
|
|
|
|
PathBuf::from(path.as_ref())
|
|
|
|
} else {
|
2021-02-14 11:00:41 -07:00
|
|
|
ProjectDirs::from("com", "elliehuxtable", "atuin")
|
|
|
|
.ok_or_else(|| {
|
2021-02-14 08:15:26 -07:00
|
|
|
eyre!("could not determine db file location\nspecify one using the --db flag")
|
2021-02-14 11:00:41 -07:00
|
|
|
})?
|
|
|
|
.data_dir()
|
|
|
|
.join("history.db")
|
2020-10-05 10:20:48 -06:00
|
|
|
};
|
|
|
|
|
2021-02-14 08:15:26 -07:00
|
|
|
let mut db = Sqlite::new(db_path)?;
|
2020-10-05 10:20:48 -06:00
|
|
|
|
2021-02-14 11:00:41 -07:00
|
|
|
self.atuin.run(&mut db)
|
2020-10-05 04:52:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2021-02-13 05:58:40 -07:00
|
|
|
Atuin::from_args().run()
|
2020-10-04 17:59:28 -06:00
|
|
|
}
|