Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix file searching
  • Loading branch information
unsecretised committed Mar 19, 2026
commit 120e0f7628a16fd4efdf8cd9d30224989c71b543
5 changes: 4 additions & 1 deletion src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
if tile.page != Page::FileSearch {
tile.handle_search_query_changed();
} else {
tile.results = search_for_file(&tile.query_lc);
tile.results = search_for_file(
&tile.query_lc,
tile.config.search_dirs.iter().map(|x| x.as_str()).collect(),
);
}

if !tile.results.is_empty() {
Expand Down
11 changes: 7 additions & 4 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Function {
}
}

pub fn search(home: &str, name: &str) -> Vec<App> {
pub fn search(home: String, name: &str) -> impl Iterator<Item = App> {
let mut builder = WalkBuilder::new(home);
builder.follow_links(false);
builder.threads(10);
Expand All @@ -137,13 +137,16 @@ pub fn search(home: &str, name: &str) -> Vec<App> {
}
})
.take(400)
.collect()
}

pub fn search_for_file(name: &str) -> Vec<App> {
pub fn search_for_file(name: &str, dirs: Vec<&str>) -> Vec<App> {
let home = std::env::var("HOME").unwrap_or_else(|_| "/".into());

search(&home, name)
dirs.iter().fold(Vec::with_capacity(400), move |vec, dir| {
let mut apps = vec.clone();
apps.extend(search(format!("{}/{}", home, dir), name));
apps
})
}

impl ToApp for DirEntry {
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Config {
pub shells: Vec<Shelly>,
pub modes: HashMap<String, String>,
pub aliases: HashMap<String, String>,
pub search_dirs: Vec<String>,
pub log_path: String,
}

Expand All @@ -43,6 +44,11 @@ impl Default for Config {
search_url: "https://google.com/search?q=%s".to_string(),
haptic_feedback: false,
show_trayicon: true,
search_dirs: vec![
"Documents".to_string(),
"Desktop".to_string(),
"Downloads".to_string(),
],
log_path: "/tmp/rustcast.log".to_string(),
modes: HashMap::new(),
aliases: HashMap::new(),
Expand Down