2021-02-14 06:28:01 -07:00
|
|
|
#![feature(proc_macro_hygiene)]
|
|
|
|
#![feature(decl_macro)]
|
|
|
|
#![warn(clippy::pedantic)]
|
|
|
|
|
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;
|
2021-02-13 13:21:49 -07:00
|
|
|
use uuid::Uuid;
|
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;
|
|
|
|
|
|
|
|
use command::{history::HistoryCmd, import::ImportCmd, server::ServerCmd};
|
2021-02-13 16:20:04 -07:00
|
|
|
use local::database::SqliteDatabase;
|
2020-10-05 10:20:48 -06:00
|
|
|
use local::history::History;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2021-02-13 12:37:00 -07:00
|
|
|
mod command;
|
|
|
|
mod local;
|
2021-02-14 06:28:01 -07:00
|
|
|
mod server;
|
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>",
|
|
|
|
version = "0.1.0",
|
|
|
|
about = "Keep your shell history in sync"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(StructOpt)]
|
2021-02-13 05:58:40 -07:00
|
|
|
enum AtuinCmd {
|
2020-10-05 04:52:03 -06:00
|
|
|
#[structopt(
|
|
|
|
about="manipulate shell history",
|
|
|
|
aliases=&["h", "hi", "his", "hist", "histo", "histor"],
|
|
|
|
)]
|
|
|
|
History(HistoryCmd),
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2020-10-05 10:20:48 -06:00
|
|
|
#[structopt(about = "import shell history from file")]
|
2021-02-13 12:37:00 -07:00
|
|
|
Import(ImportCmd),
|
2020-10-05 04:52:03 -06:00
|
|
|
|
2021-02-13 13:21:49 -07:00
|
|
|
#[structopt(about = "start an atuin server")]
|
2021-02-14 06:28:01 -07:00
|
|
|
Server(ServerCmd),
|
2021-02-13 13:21:49 -07:00
|
|
|
|
|
|
|
#[structopt(about = "generates a UUID")]
|
|
|
|
Uuid,
|
2020-10-05 04:52:03 -06:00
|
|
|
}
|
2020-10-04 17:59:28 -06:00
|
|
|
|
2021-02-13 05:58:40 -07:00
|
|
|
impl Atuin {
|
2020-10-05 10:20:48 -06:00
|
|
|
fn run(self) -> Result<()> {
|
|
|
|
let db_path = match self.db {
|
|
|
|
Some(db_path) => {
|
|
|
|
let path = db_path
|
|
|
|
.to_str()
|
|
|
|
.ok_or(eyre!("path {:?} was not valid UTF-8", db_path))?;
|
|
|
|
let path = shellexpand::full(path)?;
|
|
|
|
PathBuf::from(path.as_ref())
|
|
|
|
}
|
|
|
|
None => {
|
2021-02-13 05:58:40 -07:00
|
|
|
let project_dirs = ProjectDirs::from("com", "elliehuxtable", "atuin").ok_or(
|
|
|
|
eyre!("could not determine db file location\nspecify one using the --db flag"),
|
|
|
|
)?;
|
2020-10-05 10:20:48 -06:00
|
|
|
let root = project_dirs.data_dir();
|
|
|
|
root.join("history.db")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-13 12:37:00 -07:00
|
|
|
let mut db = SqliteDatabase::new(db_path)?;
|
2020-10-05 10:20:48 -06:00
|
|
|
|
2021-02-13 05:58:40 -07:00
|
|
|
match self.atuin {
|
2021-02-13 13:21:49 -07:00
|
|
|
AtuinCmd::History(history) => history.run(&mut db),
|
2021-02-13 12:37:00 -07:00
|
|
|
AtuinCmd::Import(import) => import.run(&mut db),
|
2021-02-14 06:28:01 -07:00
|
|
|
AtuinCmd::Server(server) => server.run(),
|
|
|
|
|
2021-02-13 13:21:49 -07:00
|
|
|
AtuinCmd::Uuid => {
|
|
|
|
println!("{}", Uuid::new_v4().to_simple().to_string());
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-10-04 17:59:28 -06:00
|
|
|
}
|
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
|
|
|
}
|