summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-09-24 22:25:23 +0200
committerCanop <cano.petrole@gmail.com>2020-09-24 22:25:23 +0200
commit6c376ca883a70aa4b646ebcedfea6a87ac52b2d7 (patch)
tree6f92b01cb3d9abe37ac2254997a2ee4356c07616 /src/command
parent60b742fceda175bd1b357280535b27ba5e915d94 (diff)
allow cmd sequences in verb execution
The syntax changed. Instead of `execution` (which is still allowed), `internal`, `external` and `cmd` are now prefered. The syntax of the `cmd` property is the same than the `--cmd` launch argument, with the added possibility to have dynamic parts. Two examples of sequence based verbs: [[verbs]] name = "myplaces" key = "ctrl-g" cmd = ":focus ~;:!focus /" [[verbs]] name = "backup" invocation = "bu {name}" cmd = ":cp {file}-back_{name};:!focus {file}-back_{name}" apply_to = "directory" Fix #277
Diffstat (limited to 'src/command')
-rw-r--r--src/command/completion.rs7
-rw-r--r--src/command/sequence.rs10
2 files changed, 9 insertions, 8 deletions
diff --git a/src/command/completion.rs b/src/command/completion.rs
index d5ec759..709765d 100644
--- a/src/command/completion.rs
+++ b/src/command/completion.rs
@@ -81,8 +81,9 @@ impl Completions {
fn for_verb(
start: &str,
con: &AppContext,
+ sel: Selection<'_>,
) -> Self {
- match con.verb_store.search(start) {
+ match con.verb_store.search(start, Some(sel.stype)) {
PrefixSearchResult::NoMatch => {
Self::None
}
@@ -146,7 +147,7 @@ impl Completions {
if arg.contains(' ') {
Self::None
} else {
- let anchor = match con.verb_store.search(verb_name) {
+ let anchor = match con.verb_store.search(verb_name, Some(sel.stype)) {
PrefixSearchResult::Match(_, verb) => verb.get_arg_anchor(),
_ => PathAnchor::Unspecified,
};
@@ -170,7 +171,7 @@ impl Completions {
match &invocation.args {
None => {
// looking into verb completion
- Self::for_verb(&invocation.name, con)
+ Self::for_verb(&invocation.name, con, sel)
}
Some(args) if !args.is_empty() => {
// looking into arg completion
diff --git a/src/command/sequence.rs b/src/command/sequence.rs
index 7856abb..1b71e7f 100644
--- a/src/command/sequence.rs
+++ b/src/command/sequence.rs
@@ -12,10 +12,10 @@ use {
/// an unparsed sequence with its separator (which may be
/// different from the one provided by local_separator())
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct Sequence {
- pub separator: String,
pub raw: String,
+ pub separator: String,
}
impl Sequence {
@@ -26,10 +26,10 @@ impl Sequence {
_ => String::from(";"),
}
}
- pub fn new(separator: String, raw: String) -> Self {
+ pub fn new(raw: String, separator: Option<String>) -> Self {
Self {
- separator,
raw,
+ separator: separator.unwrap_or_else(|| Sequence::local_separator()),
}
}
pub fn new_single(cmd: String) -> Self {
@@ -82,7 +82,7 @@ fn add_commands(
if let Command::VerbInvocate(invocation) = &command {
// we check that the verb exists to avoid running a sequence
// of actions with some missing
- match con.verb_store.search(&invocation.name) {
+ match con.verb_store.search(&invocation.name, None) {
PrefixSearchResult::NoMatch => {
return Err(ProgramError::UnknownVerb {
name: invocation.name.to_string(),