From c5c5e9d84fbbdd6c8bd59f9cea006ceb6ffce927 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Tue, 19 Nov 2024 20:02:32 +0100 Subject: feat(client): add filter mode enablement and ordering configuration (#2430) --- crates/atuin-client/config.toml | 17 ++++++++++++++--- crates/atuin-client/src/settings.rs | 38 +++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) (limited to 'crates/atuin-client') diff --git a/crates/atuin-client/config.toml b/crates/atuin-client/config.toml index 4b2810e5..388e3f85 100644 --- a/crates/atuin-client/config.toml +++ b/crates/atuin-client/config.toml @@ -40,12 +40,17 @@ ## possible values: prefix, fulltext, fuzzy, skim # search_mode = "fuzzy" -## which filter mode to use -## possible values: global, host, session, directory +## which filter mode to use by default +## possible values: "global", "host", "session", "directory", "workspace" +## consider using search.filters to customize the enablement and order of filter modes # filter_mode = "global" ## With workspace filtering enabled, Atuin will filter for commands executed -## in any directory within a git repository tree (default: false) +## in any directory within a git repository tree (default: false). +## +## To use workspace mode by default when available, set this to true and +## set filter_mode to "workspace" or leave it unspecified and +## set search.filters to include "workspace" before other filter modes. # workspaces = false ## which filter mode to use when atuin is invoked from a shell up-key binding @@ -254,3 +259,9 @@ records = true ## Whether the theme manager should output normal or extra information to help fix themes. ## Boolean, true or false. If unset, left up to the theme manager. # debug = true + +[search] +## The list of enabled filter modes, in order of priority. +## The "workspace" mode is skipped when not in a workspace or workspaces = false. +## Default filter mode can be overridden with the filter_mode setting. +# filters = [ "global", "host", "session", "workspace", "directory" ] diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index efbdb33d..10c804fa 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -370,6 +370,12 @@ pub struct Daemon { pub tcp_port: u64, } +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Search { + /// The list of enabled filter modes, in order of priority. + pub filters: Vec, +} + impl Default for Preview { fn default() -> Self { Self { @@ -400,6 +406,20 @@ impl Default for Daemon { } } +impl Default for Search { + fn default() -> Self { + Self { + filters: vec![ + FilterMode::Global, + FilterMode::Host, + FilterMode::Session, + FilterMode::Workspace, + FilterMode::Directory, + ], + } + } +} + // The preview height strategy also takes max_preview_height into account. #[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum, Serialize)] pub enum PreviewStrategy { @@ -430,7 +450,7 @@ pub struct Settings { pub key_path: String, pub session_path: String, pub search_mode: SearchMode, - pub filter_mode: FilterMode, + pub filter_mode: Option, pub filter_mode_shell_up_key_binding: Option, pub search_mode_shell_up_key_binding: Option, pub shell_up_key_binding: bool, @@ -486,6 +506,9 @@ pub struct Settings { #[serde(default)] pub daemon: Daemon, + #[serde(default)] + pub search: Search, + #[serde(default)] pub theme: Theme, } @@ -688,6 +711,13 @@ impl Settings { None } + pub fn default_filter_mode(&self) -> FilterMode { + self.filter_mode + .filter(|x| self.search.filters.contains(x)) + .or(self.search.filters.first().copied()) + .unwrap_or(FilterMode::Global) + } + #[cfg(not(feature = "check-update"))] pub async fn needs_update(&self) -> Option { None @@ -715,7 +745,7 @@ impl Settings { .set_default("sync_address", "https://api.atuin.sh")? .set_default("sync_frequency", "10m")? .set_default("search_mode", "fuzzy")? - .set_default("filter_mode", "global")? + .set_default("filter_mode", None::)? .set_default("style", "compact")? .set_default("inline_height", 40)? .set_default("show_preview", true)? @@ -758,6 +788,10 @@ impl Settings { .set_default("daemon.socket_path", socket_path.to_str())? .set_default("daemon.systemd_socket", false)? .set_default("daemon.tcp_port", 8889)? + .set_default( + "search.filters", + vec!["global", "host", "session", "workspace", "directory"], + )? .set_default("theme.name", "default")? .set_default("theme.debug", None::)? .set_default( -- cgit v1.3.1