aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/mod.rs')
-rw-r--r--src/parse/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 5059311..6ce3133 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -551,6 +551,11 @@ impl StringPart {
pub fn is_boring(&self) -> bool {
matches!(self, StringPart::Boring(..))
}
+
+ pub fn is_command(&self) -> bool {
+ matches!(self, StringPart::Cmd(..))
+ }
+
pub fn unwrap_boring(self) -> BString {
match self {
StringPart::Boring(items) => items,
@@ -588,6 +593,21 @@ impl ExpString {
}
Ok(out)
}
+
+ pub fn has_commands(&self) -> bool {
+ self.parts.iter().any(|part| part.is_command())
+ }
+
+ /// vars that are directly mentioned in this string interpolation, i.e. does not look into commands
+ pub fn vars(&self) -> Vec<BString> {
+ self.parts
+ .iter()
+ .filter_map(|part| match part {
+ StringPart::Var(var) => Some(var.name.name.clone()),
+ _ => None,
+ })
+ .collect()
+ }
}
fn is_symbol(x: u8) -> bool {