From 243a8c53ae03713b3d6b4f5bf82859f9c93be6ed Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Sat, 28 Sep 2024 14:57:03 -0600 Subject: Add support for inline environment variables This patch adds the 'Notes' rune (`=`), which allows for passing environment variables, inline, to a binary, like so: EDITOR=vim sudo visudo Signed-off-by: Rory Dudley --- src/poem/read.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/poem/read.rs') diff --git a/src/poem/read.rs b/src/poem/read.rs index 99e9aa6..baf6a1d 100644 --- a/src/poem/read.rs +++ b/src/poem/read.rs @@ -246,6 +246,7 @@ impl Readable for Poem { '#' => Rune::Remark, '\'' | '"' => Rune::String, '`' => Rune::Poem, + '=' => Rune::Notes, '<' => Rune::Read, '>' => next(&mut chars, &mut i, Rune::Write, vec![(">", Rune::Addendum)]), '1' => next( @@ -352,7 +353,11 @@ impl Readable for Poem { match rune { // Indicates the end of a word (space dilineated) Rune::Pause => { + if word.contains(&'=') && verse.is_empty() { + channel = Some(Rune::Notes); + } verse.add(&mut word, channel); + channel = Some(rune); } Rune::Special => { @@ -378,6 +383,15 @@ impl Readable for Poem { poem!(chars, j, i, c, verse, word, env); } + // Indicates an environment variable to fork with, + // if the verse's stanza is empty so far + // Rune::Environment => { + // word.push(c); + // if verse.is_empty() { + // channel = Some(rune); + // } + // } + // Indicates a file operation (<, >, or >>) Rune::Read | Rune::Write @@ -388,7 +402,7 @@ impl Readable for Poem { | Rune::AddendumAll => { channel = Some(rune); verse.add(&mut word, channel); - channel = Some(rune); + // channel = Some(rune); verse.io.push(rune); } -- cgit v1.2.3