From 41f072a8b443b5a404916598f0c9b7a52f5c05fb Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 15 Feb 2021 23:33:30 +0000 Subject: Add init command (#12) * Add init command This makes setting up the shell part of A'tuin much easier. Eval the output of "atuin init". * Update readme, add up binding --- src/command/history.rs | 6 +++--- src/command/init.rs | 19 +++++++++++++++++++ src/command/mod.rs | 5 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/command/init.rs (limited to 'src/command') diff --git a/src/command/history.rs b/src/command/history.rs index 09dd4364..bd440163 100644 --- a/src/command/history.rs +++ b/src/command/history.rs @@ -30,7 +30,7 @@ pub enum Cmd { )] List { #[structopt(long, short)] - dir: bool, + cwd: bool, #[structopt(long, short)] session: bool, @@ -77,13 +77,13 @@ impl Cmd { Ok(()) } - Self::List { session, dir, .. } => { + Self::List { session, cwd, .. } => { const QUERY_SESSION: &str = "select * from history where session = ?;"; const QUERY_DIR: &str = "select * from history where cwd = ?;"; const QUERY_SESSION_DIR: &str = "select * from history where cwd = ?1 and session = ?2;"; - let params = (session, dir); + let params = (session, cwd); let cwd = env::current_dir()?.display().to_string(); let session = env::var("ATUIN_SESSION")?; diff --git a/src/command/init.rs b/src/command/init.rs new file mode 100644 index 00000000..022021d0 --- /dev/null +++ b/src/command/init.rs @@ -0,0 +1,19 @@ +use std::env; + +use eyre::{eyre, Result}; + +fn init_zsh() { + let full = include_str!("../shell/atuin.zsh"); + println!("{}", full); +} + +pub fn init() -> Result<()> { + let shell = env::var("SHELL")?; + + if shell.ends_with("zsh") { + init_zsh(); + Ok(()) + } else { + Err(eyre!("Could not detect shell, or shell unsupported")) + } +} diff --git a/src/command/mod.rs b/src/command/mod.rs index 78e55a0d..0952540b 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -6,6 +6,7 @@ use crate::local::database::Database; mod history; mod import; +mod init; mod server; mod stats; @@ -26,6 +27,9 @@ pub enum AtuinCmd { #[structopt(about = "calculate statistics for your history")] Stats(stats::Cmd), + #[structopt(about = "output shell setup")] + Init, + #[structopt(about = "generates a UUID")] Uuid, } @@ -41,6 +45,7 @@ impl AtuinCmd { Self::Import(import) => import.run(db), Self::Server(server) => server.run(), Self::Stats(stats) => stats.run(db), + Self::Init => init::init(), Self::Uuid => { println!("{}", uuid_v4()); -- cgit v1.3.1