diff options
| author | Leonidas Loucas <311356+merc1031@users.noreply.github.com> | 2025-12-15 10:21:02 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-15 13:21:02 -0500 |
| commit | 7867eb0e785ecf7241e2e62f67b09880b42fbb0c (patch) | |
| tree | 4bd2029806d8a9011b0cf512e0d5031589469e81 /crates | |
| parent | docs: Migrate docs from separate repo to `docs` subfolder (#3018) (diff) | |
| download | atuin-7867eb0e785ecf7241e2e62f67b09880b42fbb0c.zip | |
fix: Move thorough search through search.filters w/ workspaces (#2703)
Do not just pick first from search.filters, consider all options,
filtering based on git-root and workspaces config
Fix: atuinsh/atuin#2700
Might Fix: atuinsh/atuin#2536
Wrote a few simple unit tests, and tried it by running the client
locally. Not sure about which of "[search] filters" vs "workspaces"
should be more respected, so i made it so if workspaces = false,
regardless of whats in "[search] filters" workspace gets filtered out.
First time looking at atuins code, let me know if this needs any
changes.
edit: (from my post here:
https://github.com/atuinsh/atuin/issues/2536#issuecomment-2808053862)
```
workspaces = true
[search]
filters = [ "workspace", "directory", "session", "global" ]
```
| `^R` for the ... time| in a git repo | any other dir|
| ------------- | ------------- | ------------- |
| first | workspace | directory|
| second | directory | session|
| third| session | global|
| fourth | global | directory |
| fifth | workspace | session|
| sixth | directory | global |

<!-- Thank you for making a PR! Bug fixes are always welcome, but if
you're adding a new feature or changing an existing one, we'd really
appreciate if you open an issue, post on the forum, or drop in on
Discord -->
## Checks
- [X] I am happy for maintainers to push small adjustments to this PR,
to speed up the review cycle
- [X] I have checked that there are no existing pull requests for the
same thing
- #1655 might be related, but it seems to also implement code that is
already merged, and has been open for over a year, hope its ok to
suggest this
---------
Co-authored-by: Michelle Tilley <michelle@michelletilley.net>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/atuin-client/src/settings.rs | 68 | ||||
| -rw-r--r-- | crates/atuin/src/command/client/history.rs | 5 | ||||
| -rw-r--r-- | crates/atuin/src/command/client/scripts.rs | 2 | ||||
| -rw-r--r-- | crates/atuin/src/command/client/search.rs | 2 | ||||
| -rw-r--r-- | crates/atuin/src/command/client/search/interactive.rs | 8 |
5 files changed, 74 insertions, 11 deletions
diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index 489c1a83..87ed9383 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -735,10 +735,20 @@ impl Settings { None } - pub fn default_filter_mode(&self) -> FilterMode { + pub fn default_filter_mode(&self, git_root: bool) -> FilterMode { self.filter_mode .filter(|x| self.search.filters.contains(x)) - .or(self.search.filters.first().copied()) + .or_else(|| { + self.search + .filters + .iter() + .find(|x| match (x, git_root, self.workspaces) { + (FilterMode::Workspace, true, true) => true, + (FilterMode::Workspace, _, _) => false, + (_, _, _) => true, + }) + .copied() + }) .unwrap_or(FilterMode::Global) } @@ -979,4 +989,58 @@ mod tests { Ok(()) } + + #[test] + fn can_choose_workspace_filters_when_in_git_context() -> Result<()> { + let mut settings = super::Settings::default(); + settings.search.filters = vec![ + super::FilterMode::Workspace, + super::FilterMode::Host, + super::FilterMode::Directory, + super::FilterMode::Session, + super::FilterMode::Global, + ]; + settings.workspaces = true; + + assert_eq!( + settings.default_filter_mode(true), + super::FilterMode::Workspace, + ); + + Ok(()) + } + + #[test] + fn wont_choose_workspace_filters_when_not_in_git_context() -> Result<()> { + let mut settings = super::Settings::default(); + settings.search.filters = vec![ + super::FilterMode::Workspace, + super::FilterMode::Host, + super::FilterMode::Directory, + super::FilterMode::Session, + super::FilterMode::Global, + ]; + settings.workspaces = true; + + assert_eq!(settings.default_filter_mode(false), super::FilterMode::Host,); + + Ok(()) + } + + #[test] + fn wont_choose_workspace_filters_when_workspaces_disabled() -> Result<()> { + let mut settings = super::Settings::default(); + settings.search.filters = vec![ + super::FilterMode::Workspace, + super::FilterMode::Host, + super::FilterMode::Directory, + super::FilterMode::Session, + super::FilterMode::Global, + ]; + settings.workspaces = false; + + assert_eq!(settings.default_filter_mode(true), super::FilterMode::Host,); + + Ok(()) + } } diff --git a/crates/atuin/src/command/client/history.rs b/crates/atuin/src/command/client/history.rs index 028db5f1..177ec82e 100644 --- a/crates/atuin/src/command/client/history.rs +++ b/crates/atuin/src/command/client/history.rs @@ -514,7 +514,10 @@ impl Cmd { (true, true) => [Session, Directory], (true, false) => [Session, Global], (false, true) => [Global, Directory], - (false, false) => [settings.default_filter_mode(), Global], + (false, false) => [ + settings.default_filter_mode(context.git_root.is_some()), + Global, + ], }; let history = db diff --git a/crates/atuin/src/command/client/scripts.rs b/crates/atuin/src/command/client/scripts.rs index 65ceabde..851755af 100644 --- a/crates/atuin/src/command/client/scripts.rs +++ b/crates/atuin/src/command/client/scripts.rs @@ -230,7 +230,7 @@ impl Cmd { let context = atuin_client::database::current_context(); // Get the last N+1 commands, filtering by the default mode - let filters = [settings.default_filter_mode()]; + let filters = [settings.default_filter_mode(context.git_root.is_some())]; let mut history = history_db .list(&filters, &context, Some(count), false, false) diff --git a/crates/atuin/src/command/client/search.rs b/crates/atuin/src/command/client/search.rs index 4103901a..be00ee99 100644 --- a/crates/atuin/src/command/client/search.rs +++ b/crates/atuin/src/command/client/search.rs @@ -314,7 +314,7 @@ async fn run_non_interactive( ..filter_options }; - let filter_mode = settings.default_filter_mode(); + let filter_mode = settings.default_filter_mode(context.git_root.is_some()); let results = db .search( diff --git a/crates/atuin/src/command/client/search/interactive.rs b/crates/atuin/src/command/client/search/interactive.rs index b01e75db..fc6164d6 100644 --- a/crates/atuin/src/command/client/search/interactive.rs +++ b/crates/atuin/src/command/client/search/interactive.rs @@ -18,9 +18,7 @@ use super::{ use atuin_client::{ database::{Database, current_context}, history::{History, HistoryId, HistoryStats, store::HistoryStore}, - settings::{ - CursorStyle, ExitMode, FilterMode, KeymapMode, PreviewStrategy, SearchMode, Settings, - }, + settings::{CursorStyle, ExitMode, KeymapMode, PreviewStrategy, SearchMode, Settings}, }; use crate::command::client::search::history_list::HistoryHighlighter; @@ -1260,9 +1258,7 @@ pub async fn history( filter_mode: settings .filter_mode_shell_up_key_binding .filter(|_| settings.shell_up_key_binding) - .or_else(|| Some(settings.default_filter_mode())) - .filter(|&x| x != FilterMode::Workspace || context.git_root.is_some()) - .unwrap_or(FilterMode::Global), + .unwrap_or_else(|| settings.default_filter_mode(context.git_root.is_some())), context, }, engine: engines::engine(search_mode), |
