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/atuin-client/src | |
| 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/atuin-client/src')
| -rw-r--r-- | crates/atuin-client/src/settings.rs | 68 |
1 files changed, 66 insertions, 2 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(()) + } } |
