From 7f587418daf8e7ddc5e32f06f85e9724c2ecf355 Mon Sep 17 00:00:00 2001 From: Lucas Burns <44355502+lmburns@users.noreply.github.com> Date: Sun, 13 Mar 2022 14:53:49 -0500 Subject: [PATCH] Fix `history list --cwd` errors (#278) --- Cargo.lock | 45 ------------------------------------ Cargo.toml | 1 - atuin-client/Cargo.toml | 16 +++++++++---- atuin-client/src/database.rs | 2 +- atuin-common/Cargo.toml | 2 -- atuin-server/Cargo.toml | 9 -------- atuin-server/src/router.rs | 17 +++++++------- src/command/history.rs | 4 ++-- src/command/search.rs | 13 ++++++----- 9 files changed, 29 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03d78e39..92a37f61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,7 +83,6 @@ dependencies = [ "crossbeam-channel", "directories", "eyre", - "fork", "humantime 2.1.0", "indicatif", "itertools", @@ -112,9 +111,6 @@ dependencies = [ "config", "directories", "eyre", - "fern", - "humantime 2.1.0", - "indicatif", "itertools", "log", "minspan", @@ -140,8 +136,6 @@ name = "atuin-common" version = "0.8.0" dependencies = [ "chrono", - "eyre", - "rmp-serde", "rust-crypto", "serde 1.0.132", "serde_derive", @@ -159,17 +153,10 @@ dependencies = [ "atuin-common", "base64", "chrono", - "chrono-english", "config", - "directories", "eyre", - "fern", - "fork", - "indicatif", "log", - "parse_duration", "rand 0.8.4", - "rmp-serde", "rust-crypto", "serde 1.0.132", "serde_derive", @@ -177,8 +164,6 @@ dependencies = [ "sodiumoxide", "sqlx", "tokio", - "unicode-width", - "urlencoding", "uuid", "warp", "whoami", @@ -331,17 +316,6 @@ dependencies = [ "syn", ] -[[package]] -name = "colored" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" -dependencies = [ - "atty", - "lazy_static", - "winapi", -] - [[package]] name = "config" version = "0.11.0" @@ -575,31 +549,12 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fern" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065" -dependencies = [ - "colored", - "log", -] - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fork" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c5b9b0bce249a456f83ac4404e8baad0d2ba81cf651949719a4f74eb7323bb" -dependencies = [ - "libc", -] - [[package]] name = "form_urlencoded" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index baebdfd6..a871f67a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,6 @@ tui = "0.16" termion = "1.5" unicode-width = "0.1" itertools = "0.10.3" -fork = "0.1.18" tokio = { version = "1", features = ["full"] } async-trait = "0.1.49" chrono-english = "0.1.4" diff --git a/atuin-client/Cargo.toml b/atuin-client/Cargo.toml index 3edd8756..f36e100e 100644 --- a/atuin-client/Cargo.toml +++ b/atuin-client/Cargo.toml @@ -14,12 +14,10 @@ repository = "https://github.com/ellie/atuin" atuin-common = { path = "../atuin-common", version = "0.8.0" } log = "0.4" -fern = {version = "0.6.0", features = ["colored"] } chrono = { version = "0.4", features = ["serde"] } eyre = "0.6" directories = "3" uuid = { version = "0.8", features = ["v4"] } -indicatif = "0.16.2" whoami = "1.1.2" chrono-english = "0.1.4" config = "0.11" @@ -28,7 +26,11 @@ serde = "1.0.126" serde_json = "1.0.75" rmp-serde = "0.15.5" sodiumoxide = "0.2.6" -reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features = false } +reqwest = { version = "0.11", features = [ + "blocking", + "json", + "rustls-tls", +], default-features = false } base64 = "0.13.0" parse_duration = "2.1.1" rand = "0.8.4" @@ -36,8 +38,12 @@ rust-crypto = "^0.2" tokio = { version = "1", features = ["full"] } async-trait = "0.1.49" urlencoding = "1.3.3" -humantime = "2.1.0" itertools = "0.10.3" shellexpand = "2" -sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "uuid", "chrono", "sqlite" ] } +sqlx = { version = "0.5", features = [ + "runtime-tokio-rustls", + "uuid", + "chrono", + "sqlite", +] } minspan = "0.1.1" diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 5e897cc0..3cb89472 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -283,7 +283,7 @@ impl Database for Sqlite { query: &str, ) -> Result> { let orig_query = query; - let query = query.to_string().replace("*", "%"); // allow wildcard char + let query = query.to_string().replace('*', "%"); // allow wildcard char let limit = limit.map_or("".to_owned(), |l| format!("limit {}", l)); let query = match search_mode { diff --git a/atuin-common/Cargo.toml b/atuin-common/Cargo.toml index 78626b94..efc35f43 100644 --- a/atuin-common/Cargo.toml +++ b/atuin-common/Cargo.toml @@ -14,10 +14,8 @@ repository = "https://github.com/ellie/atuin" rust-crypto = "^0.2" sodiumoxide = "0.2.6" chrono = { version = "0.4", features = ["serde"] } -eyre = "0.6" serde_derive = "1.0.125" serde = "1.0.126" serde_json = "1.0.75" -rmp-serde = "0.15.5" warp = "0.3" uuid = { version = "0.8", features = ["v4"] } diff --git a/atuin-server/Cargo.toml b/atuin-server/Cargo.toml index 4cef7089..4ad048c2 100644 --- a/atuin-server/Cargo.toml +++ b/atuin-server/Cargo.toml @@ -12,28 +12,19 @@ repository = "https://github.com/ellie/atuin" atuin-common = { path = "../atuin-common", version = "0.8.0" } log = "0.4" -fern = {version = "0.6.0", features = ["colored"] } chrono = { version = "0.4", features = ["serde"] } eyre = "0.6" -directories = "3" uuid = { version = "0.8", features = ["v4"] } -indicatif = "0.16.2" whoami = "1.1.2" -chrono-english = "0.1.4" config = "0.11" serde_derive = "1.0.125" serde = "1.0.126" serde_json = "1.0.75" -rmp-serde = "0.15.5" -unicode-width = "0.1" sodiumoxide = "0.2.6" base64 = "0.13.0" -fork = "0.1.18" -parse_duration = "2.1.1" rand = "0.8.4" rust-crypto = "^0.2" tokio = { version = "1", features = ["full"] } warp = "0.3" sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "uuid", "chrono", "postgres" ] } async-trait = "0.1.49" -urlencoding = "1.3.3" diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs index 04905a0f..f7e142a0 100644 --- a/atuin-server/src/router.rs +++ b/atuin-server/src/router.rs @@ -5,10 +5,11 @@ use warp::{hyper::StatusCode, Filter}; use atuin_common::api::SyncHistoryRequest; -use super::handlers; -use super::{database::Database, database::Postgres}; -use crate::models::User; -use crate::settings::Settings; +use super::{ + database::{Database, Postgres}, + handlers, +}; +use crate::{models::User, settings::Settings}; fn with_settings( settings: Settings, @@ -32,17 +33,15 @@ fn with_user( async move { let header: Vec<&str> = header.split(' ').collect(); - let token; - - if header.len() == 2 { + let token = if header.len() == 2 { if header[0] != "Token" { return Err(warp::reject()); } - token = header[1]; + header[1] } else { return Err(warp::reject()); - } + }; let user = postgres .get_session_user(token) diff --git a/src/command/history.rs b/src/command/history.rs index a74b210b..37b4b9dd 100644 --- a/src/command/history.rs +++ b/src/command/history.rs @@ -174,7 +174,7 @@ impl Cmd { let history = match (session, cwd) { (None, None) => db.list(None, false).await?, (None, Some(cwd)) => { - let query = format!("select * from history where cwd = {};", cwd); + let query = format!("select * from history where cwd = '{}';", cwd); db.query_history(&query).await? } (Some(session), None) => { @@ -183,7 +183,7 @@ impl Cmd { } (Some(session), Some(cwd)) => { let query = format!( - "select * from history where cwd = {} and session = {};", + "select * from history where cwd = '{}' and session = {};", cwd, session ); db.query_history(&query).await? diff --git a/src/command/search.rs b/src/command/search.rs index c9942143..6e7ec25b 100644 --- a/src/command/search.rs +++ b/src/command/search.rs @@ -1,7 +1,6 @@ use chrono::Utc; use eyre::Result; -use std::time::Duration; -use std::{io::stdout, ops::Sub}; +use std::{io::stdout, ops::Sub, time::Duration}; use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen}; use tui::{ @@ -14,9 +13,11 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; -use atuin_client::database::Database; -use atuin_client::history::History; -use atuin_client::settings::{SearchMode, Settings}; +use atuin_client::{ + database::Database, + history::History, + settings::{SearchMode, Settings}, +}; use crate::command::event::{Event, Events}; @@ -96,7 +97,7 @@ impl State { .iter() .enumerate() .map(|(i, m)| { - let command = m.command.to_string().replace("\n", " ").replace("\t", " "); + let command = m.command.to_string().replace('\n', " ").replace('\t', " "); let mut command = Span::raw(command);