diff options
| author | Pavel Ivanov <mr.pavel.ivanov@gmail.com> | 2024-11-19 20:02:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-19 11:02:32 -0800 |
| commit | c5c5e9d84fbbdd6c8bd59f9cea006ceb6ffce927 (patch) | |
| tree | 0fe228f614c692d87c68127cfc636387bb5409cf /crates/atuin-client | |
| parent | feat: right Arrow to modify selected command (#2453) (diff) | |
| download | atuin-c5c5e9d84fbbdd6c8bd59f9cea006ceb6ffce927.zip | |
feat(client): add filter mode enablement and ordering configuration (#2430)
Diffstat (limited to 'crates/atuin-client')
| -rw-r--r-- | crates/atuin-client/config.toml | 17 | ||||
| -rw-r--r-- | crates/atuin-client/src/settings.rs | 38 |
2 files changed, 50 insertions, 5 deletions
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<FilterMode>, +} + 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<FilterMode>, pub filter_mode_shell_up_key_binding: Option<FilterMode>, pub search_mode_shell_up_key_binding: Option<SearchMode>, pub shell_up_key_binding: bool, @@ -487,6 +507,9 @@ pub struct Settings { 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<Version> { 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::<String>)? .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::<bool>)? .set_default( |
