forked from skim-rs/skim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_keybinding_actions.rs
32 lines (27 loc) · 1.02 KB
/
custom_keybinding_actions.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extern crate skim;
use skim::prelude::*;
// No action is actually performed on your filesystem!
// This example only produce friendly print statements!
fn fake_delete_item(item: &str) {
println!("Deleting item `{}`...", item);
}
fn fake_create_item(item: &str) {
println!("Creating a new item `{}`...", item);
}
pub fn main() {
// Note: `accept` is a keyword used define custom actions.
// For full list of accepted keywords see `parse_event` in `src/event.rs`.
// `delete` and `create` are arbitrary keywords used for this example.
let options = SkimOptionsBuilder::default()
.multi(true)
.bind(vec!["bs:abort", "Enter:accept"])
.build()
.unwrap();
Skim::run_with(&options, None).map(|out| match out.final_key {
// Delete each selected item
Key::Backspace => out.selected_items.iter().for_each(|i| fake_delete_item(&i.text())),
// Create a new item based on the query
Key::Enter => fake_create_item(out.query.as_ref()),
_ => (),
});
}