summaryrefslogtreecommitdiffstats
path: root/src/verb/execution_builder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/verb/execution_builder.rs')
-rw-r--r--src/verb/execution_builder.rs58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/verb/execution_builder.rs b/src/verb/execution_builder.rs
index c212793..984f2e7 100644
--- a/src/verb/execution_builder.rs
+++ b/src/verb/execution_builder.rs
@@ -2,6 +2,7 @@ use {
super::*,
crate::{
app::*,
+ command::*,
path,
},
ahash::AHashMap,
@@ -46,7 +47,7 @@ impl<'b> ExecutionStringBuilder<'b> {
}
}
pub fn with_invocation(
- invocation_parser: &Option<InvocationParser>,
+ invocation_parser: Option<&InvocationParser>,
sel_info: SelInfo<'b>,
app_state: &'b AppState,
invocation_args: Option<&String>,
@@ -253,7 +254,60 @@ impl<'b> ExecutionStringBuilder<'b> {
.one_sel()
.map_or(self.root, |sel| sel.path)
}
-
+ /// replace groups in a sequence
+ ///
+ /// Replacing escapes for the shell for externals, and without
+ /// escaping for internals.
+ ///
+ /// Note that this is *before* asking the (local or remote) panel
+ /// state the sequential execution of the different commands. In
+ /// this secondary execution, new replacements are expected too,
+ /// depending on the verbs.
+ pub fn sequence(
+ &self,
+ sequence: &Sequence,
+ verb_store: &VerbStore,
+ ) -> Sequence {
+ let mut inputs = Vec::new();
+ for input in sequence.raw.split(&sequence.separator) {
+ let raw_parts = CommandParts::from(input.to_string());
+ let (_, verb_invocation) = raw_parts.split();
+ let verb_is_external = verb_invocation
+ .and_then(|vi| {
+ let command = Command::from_parts(vi, true);
+ if let Command::VerbInvocate(invocation) = &command {
+ let search = verb_store.search_prefix(&invocation.name);
+ if let PrefixSearchResult::Match(_, verb) = search {
+ return Some(verb);
+ }
+ }
+ None
+ })
+ .map_or(false, |verb| verb.get_internal().is_none());
+ let input = if verb_is_external {
+ self.shell_exec_string(&ExecPattern::from_string(input))
+ } else {
+ self.string(&input)
+ };
+ inputs.push(input);
+ }
+ Sequence {
+ raw: inputs.join(&sequence.separator),
+ separator: sequence.separator.clone(),
+ }
+ }
+ /// build a raw string, without escapings
+ pub fn string(
+ &self,
+ pattern: &str,
+ ) -> String {
+ GROUP
+ .replace_all(
+ pattern,
+ |ec: &Captures<'_>| self.get_capture_replacement(ec),
+ )
+ .to_string()
+ }
/// build a path
pub fn path(
&self,