Skip to content

Commit 3e4c6e2

Browse files
authored
Merge pull request #199 from unsecretised/file-search-fix
fix file searching
2 parents 0dbd30f + b26fbf7 commit 3e4c6e2

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/app/tile/update.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
535535
if tile.page != Page::FileSearch {
536536
tile.handle_search_query_changed();
537537
} else {
538-
tile.results = search_for_file(&tile.query_lc);
538+
tile.results = search_for_file(
539+
&tile.query_lc,
540+
tile.config.search_dirs.iter().map(|x| x.as_str()).collect(),
541+
);
539542
}
540543

541544
if !tile.results.is_empty() {

src/commands.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Function {
116116
}
117117
}
118118

119-
pub fn search(home: &str, name: &str) -> Vec<App> {
119+
pub fn search(home: String, name: &str) -> impl Iterator<Item = App> {
120120
let mut builder = WalkBuilder::new(home);
121121
builder.follow_links(false);
122122
builder.threads(10);
@@ -137,13 +137,16 @@ pub fn search(home: &str, name: &str) -> Vec<App> {
137137
}
138138
})
139139
.take(400)
140-
.collect()
141140
}
142141

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

146-
search(&home, name)
145+
dirs.iter().fold(Vec::with_capacity(400), move |vec, dir| {
146+
let mut apps = vec.clone();
147+
apps.extend(search(dir.replace("~", &home), name));
148+
apps
149+
})
147150
}
148151

149152
impl ToApp for DirEntry {

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct Config {
2828
pub shells: Vec<Shelly>,
2929
pub modes: HashMap<String, String>,
3030
pub aliases: HashMap<String, String>,
31+
pub search_dirs: Vec<String>,
3132
pub log_path: String,
3233
}
3334

@@ -43,6 +44,11 @@ impl Default for Config {
4344
search_url: "https://google.com/search?q=%s".to_string(),
4445
haptic_feedback: false,
4546
show_trayicon: true,
47+
search_dirs: vec![
48+
"~/Documents".to_string(),
49+
"~/Desktop".to_string(),
50+
"~/Downloads".to_string(),
51+
],
4652
log_path: "/tmp/rustcast.log".to_string(),
4753
modes: HashMap::new(),
4854
aliases: HashMap::new(),

0 commit comments

Comments
 (0)