From 63cd972515f61b451bf173881419d2a620ac0672 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Thu, 28 Sep 2023 11:32:11 +0100 Subject: [PATCH 1/3] clear history id --- atuin/src/command/client.rs | 4 +++- atuin/src/command/client/account.rs | 4 ++-- atuin/src/command/client/account/login.rs | 2 +- atuin/src/command/client/account/register.rs | 2 +- atuin/src/command/client/history.rs | 2 +- atuin/src/command/client/import.rs | 2 +- atuin/src/command/client/kv.rs | 2 +- atuin/src/command/client/search.rs | 2 +- atuin/src/command/client/stats.rs | 2 +- atuin/src/command/client/sync.rs | 2 +- atuin/src/command/server.rs | 4 +++- atuin/src/shell/atuin.bash | 5 +++-- atuin/src/shell/atuin.fish | 5 +++-- atuin/src/shell/atuin.nu | 5 +++-- atuin/src/shell/atuin.zsh | 5 +++-- 15 files changed, 28 insertions(+), 20 deletions(-) diff --git a/atuin/src/command/client.rs b/atuin/src/command/client.rs index a4910f1e8f3..d2c14ee67e3 100644 --- a/atuin/src/command/client.rs +++ b/atuin/src/command/client.rs @@ -18,7 +18,7 @@ mod kv; mod search; mod stats; -#[derive(Subcommand)] +#[derive(Subcommand, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { /// Manipulate shell history @@ -54,6 +54,8 @@ impl Cmd { .parse_env("ATUIN_LOG") .init(); + tracing::trace!(command = ?self, "client command"); + let mut settings = Settings::new().wrap_err("could not load client settings")?; let db_path = PathBuf::from(settings.db_path.as_str()); diff --git a/atuin/src/command/client/account.rs b/atuin/src/command/client/account.rs index 2a4a077275d..657552fb6b8 100644 --- a/atuin/src/command/client/account.rs +++ b/atuin/src/command/client/account.rs @@ -8,13 +8,13 @@ pub mod login; pub mod logout; pub mod register; -#[derive(Args)] +#[derive(Args, Debug)] pub struct Cmd { #[command(subcommand)] command: Commands, } -#[derive(Subcommand)] +#[derive(Subcommand, Debug)] pub enum Commands { /// Login to the configured server Login(login::Cmd), diff --git a/atuin/src/command/client/account/login.rs b/atuin/src/command/client/account/login.rs index 9bfe0b406d0..24f54ec298b 100644 --- a/atuin/src/command/client/account/login.rs +++ b/atuin/src/command/client/account/login.rs @@ -12,7 +12,7 @@ use atuin_client::{ use atuin_common::api::LoginRequest; use rpassword::prompt_password; -#[derive(Parser)] +#[derive(Parser, Debug)] pub struct Cmd { #[clap(long, short)] pub username: Option, diff --git a/atuin/src/command/client/account/register.rs b/atuin/src/command/client/account/register.rs index d306a141997..f8c0eafc3ca 100644 --- a/atuin/src/command/client/account/register.rs +++ b/atuin/src/command/client/account/register.rs @@ -4,7 +4,7 @@ use tokio::{fs::File, io::AsyncWriteExt}; use atuin_client::{api_client, settings::Settings}; -#[derive(Parser)] +#[derive(Parser, Debug)] pub struct Cmd { #[clap(long, short)] pub username: Option, diff --git a/atuin/src/command/client/history.rs b/atuin/src/command/client/history.rs index c9e0dd037b6..f3a7dabdfe5 100644 --- a/atuin/src/command/client/history.rs +++ b/atuin/src/command/client/history.rs @@ -23,7 +23,7 @@ use time::{macros::format_description, OffsetDateTime}; use super::search::format_duration_into; -#[derive(Subcommand)] +#[derive(Subcommand, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { /// Begins a new command in the history diff --git a/atuin/src/command/client/import.rs b/atuin/src/command/client/import.rs index 7abc3d4428d..4aa70a0a02d 100644 --- a/atuin/src/command/client/import.rs +++ b/atuin/src/command/client/import.rs @@ -14,7 +14,7 @@ use atuin_client::{ }, }; -#[derive(Parser)] +#[derive(Parser, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { /// Import history for the current shell diff --git a/atuin/src/command/client/kv.rs b/atuin/src/command/client/kv.rs index d9a2276046c..48ebe9e5a96 100644 --- a/atuin/src/command/client/kv.rs +++ b/atuin/src/command/client/kv.rs @@ -3,7 +3,7 @@ use eyre::{Context, Result}; use atuin_client::{encryption, kv::KvStore, record::store::Store, settings::Settings}; -#[derive(Subcommand)] +#[derive(Subcommand, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { // atuin kv set foo bar bar diff --git a/atuin/src/command/client/search.rs b/atuin/src/command/client/search.rs index e5e4a9a3155..cb102871f13 100644 --- a/atuin/src/command/client/search.rs +++ b/atuin/src/command/client/search.rs @@ -19,7 +19,7 @@ mod interactive; pub use duration::{format_duration, format_duration_into}; #[allow(clippy::struct_excessive_bools)] -#[derive(Parser)] +#[derive(Parser, Debug)] pub struct Cmd { /// Filter search result by directory #[arg(long, short)] diff --git a/atuin/src/command/client/stats.rs b/atuin/src/command/client/stats.rs index 08145027c48..f3e2094b2b4 100644 --- a/atuin/src/command/client/stats.rs +++ b/atuin/src/command/client/stats.rs @@ -12,7 +12,7 @@ use atuin_client::{ }; use time::{Duration, OffsetDateTime, Time}; -#[derive(Parser)] +#[derive(Parser, Debug)] #[command(infer_subcommands = true)] pub struct Cmd { /// compute statistics for the specified period, leave blank for statistics since the beginning diff --git a/atuin/src/command/client/sync.rs b/atuin/src/command/client/sync.rs index d8c0a58bfa4..7e107adbba9 100644 --- a/atuin/src/command/client/sync.rs +++ b/atuin/src/command/client/sync.rs @@ -11,7 +11,7 @@ mod status; use crate::command::client::account; -#[derive(Subcommand)] +#[derive(Subcommand, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { /// Sync with the configured server diff --git a/atuin/src/command/server.rs b/atuin/src/command/server.rs index c65cb505984..c02c4007121 100644 --- a/atuin/src/command/server.rs +++ b/atuin/src/command/server.rs @@ -6,7 +6,7 @@ use eyre::{Context, Result}; use atuin_server::{launch, Settings}; -#[derive(Parser)] +#[derive(Parser, Debug)] #[clap(infer_subcommands = true)] pub enum Cmd { /// Start the server @@ -29,6 +29,8 @@ impl Cmd { .with(EnvFilter::from_default_env()) .init(); + tracing::trace!(command = ?self, "server command"); + let settings = Settings::new().wrap_err("could not load server settings")?; match self { diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index fd78ee3a688..7b862bf7128 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -12,12 +12,13 @@ _atuin_precmd() { [[ -z "${ATUIN_HISTORY_ID}" ]] && return - (RUST_LOG=error atuin history end --exit "${EXIT}" -- "${ATUIN_HISTORY_ID}" &) >/dev/null 2>&1 + (ATUIN_LOG=error atuin history end --exit "${EXIT}" -- "${ATUIN_HISTORY_ID}" &) >/dev/null 2>&1 + export ATUIN_HISTORY_ID="" } __atuin_history() { # shellcheck disable=SC2048,SC2086 - HISTORY="$(RUST_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)" + HISTORY="$(ATUIN_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)" READLINE_LINE=${HISTORY} READLINE_POINT=${#READLINE_LINE} diff --git a/atuin/src/shell/atuin.fish b/atuin/src/shell/atuin.fish index 344c7d1941c..5b7b64e8081 100644 --- a/atuin/src/shell/atuin.fish +++ b/atuin/src/shell/atuin.fish @@ -9,13 +9,14 @@ end function _atuin_postexec --on-event fish_postexec set s $status if test -n "$ATUIN_HISTORY_ID" - RUST_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null & + ATUIN_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null & disown end + set --erase ATUIN_HISTORY_ID end function _atuin_search - set h (RUST_LOG=error atuin search $argv -i -- (commandline -b) 3>&1 1>&2 2>&3) + set h (ATUIN_LOG=error atuin search $argv -i -- (commandline -b) 3>&1 1>&2 2>&3) commandline -f repaint if test -n "$h" commandline -r "$h" diff --git a/atuin/src/shell/atuin.nu b/atuin/src/shell/atuin.nu index 673e99d0570..3c49fe5d9cc 100644 --- a/atuin/src/shell/atuin.nu +++ b/atuin/src/shell/atuin.nu @@ -19,16 +19,17 @@ let _atuin_pre_prompt = {|| if 'ATUIN_HISTORY_ID' not-in $env { return } - with-env { RUST_LOG: error } { + with-env { ATUIN_LOG: error } { atuin history end $'--exit=($last_exit)' -- $env.ATUIN_HISTORY_ID | null } + $env.ATUIN_HISTORY_ID = "" } def _atuin_search_cmd [...flags: string] { [ $ATUIN_KEYBINDING_TOKEN, ([ - `commandline (RUST_LOG=error run-external --redirect-stderr atuin search`, + `commandline (ATUIN_LOG=error run-external --redirect-stderr atuin search`, ($flags | append [--interactive, --] | each {|e| $'"($e)"'}), `(commandline) | complete | $in.stderr | str substring ..-1)`, ] | flatten | str join ' '), diff --git a/atuin/src/shell/atuin.zsh b/atuin/src/shell/atuin.zsh index 2ea4f4d748f..edea0c807e7 100644 --- a/atuin/src/shell/atuin.zsh +++ b/atuin/src/shell/atuin.zsh @@ -23,7 +23,8 @@ _atuin_precmd() { [[ -z "${ATUIN_HISTORY_ID:-}" ]] && return - (RUST_LOG=error atuin history end --exit $EXIT -- $ATUIN_HISTORY_ID &) >/dev/null 2>&1 + (ATUIN_LOG=error atuin history end --exit $EXIT -- $ATUIN_HISTORY_ID &) >/dev/null 2>&1 + export ATUIN_HISTORY_ID="" } _atuin_search() { @@ -33,7 +34,7 @@ _atuin_search() { # swap stderr and stdout, so that the tui stuff works # TODO: not this # shellcheck disable=SC2048 - output=$(RUST_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3) + output=$(ATUIN_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3) if [[ -n $output ]]; then RBUFFER="" From 24ff75d7e4e4f5c3b15df4106458922f9f813873 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 8 Oct 2023 15:30:36 +0100 Subject: [PATCH 2/3] fix nu --- atuin/src/shell/atuin.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atuin/src/shell/atuin.nu b/atuin/src/shell/atuin.nu index 3c49fe5d9cc..1361bda63f0 100644 --- a/atuin/src/shell/atuin.nu +++ b/atuin/src/shell/atuin.nu @@ -22,7 +22,7 @@ let _atuin_pre_prompt = {|| with-env { ATUIN_LOG: error } { atuin history end $'--exit=($last_exit)' -- $env.ATUIN_HISTORY_ID | null } - $env.ATUIN_HISTORY_ID = "" + hide-env ATUIN_HISTORY_ID } def _atuin_search_cmd [...flags: string] { From e194be21d581cbc587001fd5c5857ee6e42936d8 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 8 Oct 2023 16:41:54 +0100 Subject: [PATCH 3/3] make clippy happy --- atuin-client/src/database.rs | 8 ++++---- atuin-client/src/sync.rs | 6 +++--- atuin/src/command/client.rs | 10 +++++----- atuin/src/command/client/history.rs | 9 ++++----- atuin/src/command/client/import.rs | 8 ++++---- atuin/src/command/client/search.rs | 9 ++++----- atuin/src/command/client/stats.rs | 2 +- atuin/src/command/client/sync.rs | 4 ++-- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index c75a32ceb4d..a7be9436d9e 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -70,8 +70,8 @@ pub fn current_context() -> Context { #[async_trait] pub trait Database: Send + Sync + 'static { - async fn save(&mut self, h: &History) -> Result<()>; - async fn save_bulk(&mut self, h: &[History]) -> Result<()>; + async fn save(&self, h: &History) -> Result<()>; + async fn save_bulk(&self, h: &[History]) -> Result<()>; async fn load(&self, id: &str) -> Result>; async fn list( @@ -193,7 +193,7 @@ impl Sqlite { #[async_trait] impl Database for Sqlite { - async fn save(&mut self, h: &History) -> Result<()> { + async fn save(&self, h: &History) -> Result<()> { debug!("saving history to sqlite"); let mut tx = self.pool.begin().await?; Self::save_raw(&mut tx, h).await?; @@ -202,7 +202,7 @@ impl Database for Sqlite { Ok(()) } - async fn save_bulk(&mut self, h: &[History]) -> Result<()> { + async fn save_bulk(&self, h: &[History]) -> Result<()> { debug!("saving history to sqlite"); let mut tx = self.pool.begin().await?; diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs index c2fc75f986d..5f612c715a7 100644 --- a/atuin-client/src/sync.rs +++ b/atuin-client/src/sync.rs @@ -37,7 +37,7 @@ async fn sync_download( key: &Key, force: bool, client: &api_client::Client<'_>, - db: &mut (impl Database + Send), + db: &(impl Database + Send), ) -> Result<(i64, i64)> { debug!("starting sync download"); @@ -127,7 +127,7 @@ async fn sync_upload( key: &Key, _force: bool, client: &api_client::Client<'_>, - db: &mut (impl Database + Send), + db: &(impl Database + Send), ) -> Result<()> { debug!("starting sync upload"); @@ -188,7 +188,7 @@ async fn sync_upload( Ok(()) } -pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Send)) -> Result<()> { +pub async fn sync(settings: &Settings, force: bool, db: &(impl Database + Send)) -> Result<()> { let client = api_client::Client::new( &settings.sync_address, &settings.session_token, diff --git a/atuin/src/command/client.rs b/atuin/src/command/client.rs index d2c14ee67e3..7124ca99958 100644 --- a/atuin/src/command/client.rs +++ b/atuin/src/command/client.rs @@ -61,17 +61,17 @@ impl Cmd { let db_path = PathBuf::from(settings.db_path.as_str()); let record_store_path = PathBuf::from(settings.record_store_path.as_str()); - let mut db = Sqlite::new(db_path).await?; + let db = Sqlite::new(db_path).await?; let mut store = SqliteStore::new(record_store_path).await?; match self { - Self::History(history) => history.run(&settings, &mut db).await, - Self::Import(import) => import.run(&mut db).await, - Self::Stats(stats) => stats.run(&mut db, &settings).await, + Self::History(history) => history.run(&settings, &db).await, + Self::Import(import) => import.run(&db).await, + Self::Stats(stats) => stats.run(&db, &settings).await, Self::Search(search) => search.run(db, &mut settings).await, #[cfg(feature = "sync")] - Self::Sync(sync) => sync.run(settings, &mut db, &mut store).await, + Self::Sync(sync) => sync.run(settings, &db, &mut store).await, #[cfg(feature = "sync")] Self::Account(account) => account.run(settings).await, diff --git a/atuin/src/command/client/history.rs b/atuin/src/command/client/history.rs index f3a7dabdfe5..8cf35d5b20e 100644 --- a/atuin/src/command/client/history.rs +++ b/atuin/src/command/client/history.rs @@ -239,7 +239,7 @@ fn parse_fmt(format: &str) -> ParsedFmt { impl Cmd { #[allow(clippy::too_many_lines, clippy::cast_possible_truncation)] async fn handle_start( - db: &mut impl Database, + db: &impl Database, settings: &Settings, command: &[String], ) -> Result<()> { @@ -268,7 +268,7 @@ impl Cmd { } async fn handle_end( - db: &mut impl Database, + db: &impl Database, settings: &Settings, id: &str, exit: i64, @@ -313,7 +313,7 @@ impl Cmd { #[allow(clippy::too_many_arguments)] #[allow(clippy::fn_params_excessive_bools)] async fn handle_list( - db: &mut impl Database, + db: &impl Database, settings: &Settings, context: atuin_client::database::Context, session: bool, @@ -361,7 +361,7 @@ impl Cmd { Ok(()) } - pub async fn run(self, settings: &Settings, db: &mut impl Database) -> Result<()> { + pub async fn run(self, settings: &Settings, db: &impl Database) -> Result<()> { let context = current_context(); match self { @@ -377,7 +377,6 @@ impl Cmd { format, } => { let mode = ListMode::from_flags(human, cmd_only); - let reverse = reverse; Self::handle_list( db, settings, context, session, cwd, mode, format, false, print0, reverse, ) diff --git a/atuin/src/command/client/import.rs b/atuin/src/command/client/import.rs index 4aa70a0a02d..fbb63818769 100644 --- a/atuin/src/command/client/import.rs +++ b/atuin/src/command/client/import.rs @@ -39,7 +39,7 @@ pub enum Cmd { const BATCH_SIZE: usize = 100; impl Cmd { - pub async fn run(&self, db: &mut DB) -> Result<()> { + pub async fn run(&self, db: &DB) -> Result<()> { println!(" Atuin "); println!("======================"); println!(" \u{1f30d} "); @@ -104,11 +104,11 @@ impl Cmd { pub struct HistoryImporter<'db, DB: Database> { pb: ProgressBar, buf: Vec, - db: &'db mut DB, + db: &'db DB, } impl<'db, DB: Database> HistoryImporter<'db, DB> { - fn new(db: &'db mut DB, len: usize) -> Self { + fn new(db: &'db DB, len: usize) -> Self { Self { pb: ProgressBar::new(len as u64), buf: Vec::with_capacity(BATCH_SIZE), @@ -138,7 +138,7 @@ impl<'db, DB: Database> Loader for HistoryImporter<'db, DB> { } } -async fn import(db: &mut DB) -> Result<()> { +async fn import(db: &DB) -> Result<()> { println!("Importing history from {}", I::NAME); let mut importer = I::new().await?; diff --git a/atuin/src/command/client/search.rs b/atuin/src/command/client/search.rs index cb102871f13..2297d81b88d 100644 --- a/atuin/src/command/client/search.rs +++ b/atuin/src/command/client/search.rs @@ -103,7 +103,7 @@ pub struct Cmd { } impl Cmd { - pub async fn run(self, mut db: impl Database, settings: &mut Settings) -> Result<()> { + pub async fn run(self, db: impl Database, settings: &mut Settings) -> Result<()> { if self.delete && self.query.is_empty() { println!("Please specify a query to match the items you wish to delete. If you wish to delete all history, pass --delete-it-all"); return Ok(()); @@ -147,7 +147,7 @@ impl Cmd { }; let mut entries = - run_non_interactive(settings, opt_filter.clone(), &self.query, &mut db).await?; + run_non_interactive(settings, opt_filter.clone(), &self.query, &db).await?; if entries.is_empty() { std::process::exit(1) @@ -165,8 +165,7 @@ impl Cmd { } entries = - run_non_interactive(settings, opt_filter.clone(), &self.query, &mut db) - .await?; + run_non_interactive(settings, opt_filter.clone(), &self.query, &db).await?; } } else { super::history::print_list( @@ -189,7 +188,7 @@ async fn run_non_interactive( settings: &Settings, filter_options: OptFilters, query: &[String], - db: &mut impl Database, + db: &impl Database, ) -> Result> { let dir = if filter_options.cwd.as_deref() == Some(".") { Some(utils::get_current_dir()) diff --git a/atuin/src/command/client/stats.rs b/atuin/src/command/client/stats.rs index f3e2094b2b4..625c6beb678 100644 --- a/atuin/src/command/client/stats.rs +++ b/atuin/src/command/client/stats.rs @@ -73,7 +73,7 @@ fn compute_stats(history: &[History], count: usize) -> Result<()> { } impl Cmd { - pub async fn run(&self, db: &mut impl Database, settings: &Settings) -> Result<()> { + pub async fn run(&self, db: &impl Database, settings: &Settings) -> Result<()> { let context = current_context(); let words = if self.period.is_empty() { String::from("all") diff --git a/atuin/src/command/client/sync.rs b/atuin/src/command/client/sync.rs index 7e107adbba9..50a1d8352bd 100644 --- a/atuin/src/command/client/sync.rs +++ b/atuin/src/command/client/sync.rs @@ -44,7 +44,7 @@ impl Cmd { pub async fn run( self, settings: Settings, - db: &mut impl Database, + db: &impl Database, store: &mut (impl Store + Send + Sync), ) -> Result<()> { match self { @@ -74,7 +74,7 @@ impl Cmd { async fn run( settings: &Settings, force: bool, - db: &mut impl Database, + db: &impl Database, store: &mut (impl Store + Send + Sync), ) -> Result<()> { let (diff, remote_index) = sync::diff(settings, store).await?;