Skip to content

Commit ce90373

Browse files
author
LoricAndre
committed
feat: add reload action
1 parent 7df8b77 commit ce90373

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

skim/src/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum Event {
5252
EvActPreviewPageDown(i32),
5353
EvActPreviousHistory,
5454
EvActRedraw,
55+
EvActReload(Option<String>),
5556
EvActRefreshCmd,
5657
EvActRefreshPreview,
5758
EvActRotateMode,
@@ -129,6 +130,7 @@ pub fn parse_event(action: &str, arg: Option<String>) -> Option<Event> {
129130
"previous-history" => Some(Event::EvActPreviousHistory),
130131
"refresh-cmd" => Some(Event::EvActRefreshCmd),
131132
"refresh-preview" => Some(Event::EvActRefreshPreview),
133+
"reload" => Some(Event::EvActReload(arg.clone())),
132134
"scroll-left" => Some(Event::EvActScrollLeft(arg.and_then(|s|s.parse().ok()).unwrap_or(1))),
133135
"scroll-right" => Some(Event::EvActScrollRight(arg.and_then(|s|s.parse().ok()).unwrap_or(1))),
134136
"select-all" => Some(Event::EvActSelectAll),

skim/src/model.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ impl Model {
436436
let _ = Command::new(shell).arg("-c").arg(cmd).status();
437437
}
438438

439+
fn act_reload(&mut self, cmd_opt: Option<String>) {
440+
let cmd = match cmd_opt {
441+
Some(s) => s,
442+
None => self.query.get_cmd(),
443+
};
444+
debug!("command to execute: [{}]", cmd);
445+
let mut env = ModelEnv {
446+
cmd: cmd.to_string(),
447+
cmd_query: self.query.get_cmd_query(),
448+
query: self.query.get_fz_query(),
449+
clear_selection: ClearStrategy::ClearIfNotNull,
450+
in_query_mode: self.query.in_query_mode(),
451+
};
452+
453+
self.selection.clear();
454+
self.on_cmd_query_change(&mut env);
455+
}
456+
439457
#[allow(clippy::trivial_regex)]
440458
fn act_append_and_select(&mut self, env: &mut ModelEnv) {
441459
let query = self.query.get_fz_query();
@@ -567,6 +585,10 @@ impl Model {
567585
self.act_execute_silent(cmd);
568586
}
569587

588+
Event::EvActReload(ref cmd) => {
589+
self.act_reload(cmd.clone());
590+
}
591+
570592
Event::EvActAppendAndSelect => {
571593
self.act_append_and_select(&mut env);
572594
}

skim/src/options.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ pub struct SkimOptions {
244244
/// preview-page-down
245245
/// preview-page-up
246246
/// previous-history (ctrl-p on --history or --cmd-history)
247+
/// reload(...)
247248
/// select-all
248249
/// toggle
249250
/// toggle-all
@@ -263,10 +264,11 @@ pub struct SkimOptions {
263264
///
264265
/// sk --bind 'ctrl-a:select-all+accept'
265266
///
266-
/// With execute(...) action, you can execute arbitrary commands without leaving sk. For example,
267+
/// With execute(...) and reload(...) action, you can execute arbitrary commands without leaving sk. For example,
267268
/// you can turn sk into a simple file browser by binding enter key to less command like follows.
268269
///
269270
/// sk --bind "enter:execute(less {})"
271+
/// Note: if no argument is supplied to reload, the default command is run.
270272
///
271273
/// You can use the same placeholder expressions as in --preview.
272274
///

0 commit comments

Comments
 (0)