From 4512cd5c7f853700c5ace9d318f25f210798a759 Mon Sep 17 00:00:00 2001 From: jfmontanaro Date: Thu, 15 Feb 2024 11:33:30 -0800 Subject: fix(xonsh): Add xonsh to auto import, respect $HISTFILE in xonsh import, and fix issue with up-arrow keybinding in xonsh (#1711) * add xonsh to `atuin import auto` * respect $HISTFILE in xonsh importers * disable up-arrow binding in xonsh when completion menu is active * include xonsh logic in the same conditional as other shells * format and fix clippy lints --- atuin-client/src/import/xonsh.rs | 10 ++++++---- atuin-client/src/import/xonsh_sqlite.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'atuin-client/src') diff --git a/atuin-client/src/import/xonsh.rs b/atuin-client/src/import/xonsh.rs index 2269212f..8a37c715 100644 --- a/atuin-client/src/import/xonsh.rs +++ b/atuin-client/src/import/xonsh.rs @@ -10,7 +10,7 @@ use time::OffsetDateTime; use uuid::timestamp::{context::NoContext, Timestamp}; use uuid::Uuid; -use super::{Importer, Loader}; +use super::{get_histpath, Importer, Loader}; use crate::history::History; // Note: both HistoryFile and HistoryData have other keys present in the JSON, we don't @@ -41,7 +41,7 @@ pub struct Xonsh { hostname: String, } -fn get_hist_dir(xonsh_data_dir: Option) -> Result { +fn xonsh_hist_dir(xonsh_data_dir: Option) -> Result { // if running within xonsh, this will be available if let Some(d) = xonsh_data_dir { let mut path = PathBuf::from(d); @@ -107,7 +107,9 @@ impl Importer for Xonsh { const NAME: &'static str = "xonsh"; async fn new() -> Result { - let hist_dir = get_hist_dir(env::var("XONSH_DATA_DIR").ok())?; + // wrap xonsh-specific path resolver in general one so that it respects $HISTPATH + let xonsh_data_dir = env::var("XONSH_DATA_DIR").ok(); + let hist_dir = get_histpath(|| xonsh_hist_dir(xonsh_data_dir))?; let sessions = load_sessions(&hist_dir)?; let hostname = get_hostname(); Ok(Xonsh { sessions, hostname }) @@ -167,7 +169,7 @@ mod tests { #[test] fn test_hist_dir_xonsh() { - let hist_dir = get_hist_dir(Some("/home/user/xonsh_data".to_string())).unwrap(); + let hist_dir = xonsh_hist_dir(Some("/home/user/xonsh_data".to_string())).unwrap(); assert_eq!( hist_dir, PathBuf::from("/home/user/xonsh_data/history_json") diff --git a/atuin-client/src/import/xonsh_sqlite.rs b/atuin-client/src/import/xonsh_sqlite.rs index 8310c375..de59d477 100644 --- a/atuin-client/src/import/xonsh_sqlite.rs +++ b/atuin-client/src/import/xonsh_sqlite.rs @@ -10,7 +10,7 @@ use time::OffsetDateTime; use uuid::timestamp::{context::NoContext, Timestamp}; use uuid::Uuid; -use super::{Importer, Loader}; +use super::{get_histpath, Importer, Loader}; use crate::history::History; #[derive(Debug, FromRow)] @@ -57,7 +57,7 @@ impl HistDbEntry { } } -fn get_db_path(xonsh_data_dir: Option) -> Result { +fn xonsh_db_path(xonsh_data_dir: Option) -> Result { // if running within xonsh, this will be available if let Some(d) = xonsh_data_dir { let mut path = PathBuf::from(d); @@ -98,7 +98,9 @@ impl Importer for XonshSqlite { const NAME: &'static str = "xonsh_sqlite"; async fn new() -> Result { - let db_path = get_db_path(env::var("XONSH_DATA_DIR").ok())?; + // wrap xonsh-specific path resolver in general one so that it respects $HISTPATH + let xonsh_data_dir = env::var("XONSH_DATA_DIR").ok(); + let db_path = get_histpath(|| xonsh_db_path(xonsh_data_dir))?; let connection_str = db_path.to_str().ok_or_else(|| { eyre!( "Invalid path for SQLite database: {}", @@ -151,7 +153,7 @@ mod tests { #[test] fn test_db_path_xonsh() { - let db_path = get_db_path(Some("/home/user/xonsh_data".to_string())).unwrap(); + let db_path = xonsh_db_path(Some("/home/user/xonsh_data".to_string())).unwrap(); assert_eq!( db_path, PathBuf::from("/home/user/xonsh_data/xonsh-history.sqlite") -- cgit v1.3.1