Skip to content

Commit 2c528f1

Browse files
committed
plugins/applications: Add entry priority
1 parent 8cf7bd9 commit 2c528f1

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

plugins/applications/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ Config(
3131
// {} is replaced with the command in the desktop entry
3232
args: "-e {}",
3333
)),
34+
35+
// Whether to prioritize actions or applications
36+
// Could be ActionsFirst, ApplicationsFirst, or NoPriority
37+
entry_priority: Some(ActionsFirst),
3438
)
3539
```

plugins/applications/src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Config {
1111
max_entries: usize,
1212
terminal: Option<Terminal>,
1313
preprocess_exec_script: Option<PathBuf>,
14+
entry_priority: Option<EntryPriority>,
1415
}
1516

1617
#[derive(Deserialize)]
@@ -19,13 +20,21 @@ pub struct Terminal {
1920
args: String,
2021
}
2122

23+
#[derive(Deserialize)]
24+
pub enum EntryPriority {
25+
ActionsFirst,
26+
ApplicationsFirst,
27+
NoPriority,
28+
}
29+
2230
impl Default for Config {
2331
fn default() -> Self {
2432
Self {
2533
desktop_actions: false,
2634
max_entries: 5,
2735
preprocess_exec_script: None,
2836
terminal: None,
37+
entry_priority: None,
2938
}
3039
}
3140
}
@@ -177,6 +186,12 @@ pub fn init(config_dir: RString) -> State {
177186
#[get_matches]
178187
pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
179188
let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case();
189+
let entry_priority = state
190+
.config
191+
.entry_priority
192+
.as_ref()
193+
.unwrap_or(&EntryPriority::ActionsFirst);
194+
180195
let mut entries = state
181196
.entries
182197
.iter()
@@ -200,10 +215,12 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
200215

201216
let mut score = (name_score * 10 + desc_score + keyword_score) - entry.offset;
202217

203-
// prioritize actions
204-
if entry.is_action {
205-
score *= 2;
206-
}
218+
// Apply priority
219+
score *= match (entry_priority, entry.is_action) {
220+
(EntryPriority::ActionsFirst, true) => 2,
221+
(EntryPriority::ApplicationsFirst, false) => 2,
222+
_ => 1,
223+
};
207224

208225
// Score cutoff
209226
if score > 0 {

0 commit comments

Comments
 (0)