diff options
author | Rory Dudley | 2024-09-28 14:57:03 -0600 |
---|---|---|
committer | Rory Dudley | 2024-09-28 19:54:50 -0600 |
commit | 243a8c53ae03713b3d6b4f5bf82859f9c93be6ed (patch) | |
tree | 2bca8a92ec89707eebb00fd8b46f32e3a82466bb /src/poem/read.rs | |
parent | 97ca3fa5197599ec28b19d5b2048f7c24e4c8bbc (diff) | |
download | dwarvish-243a8c53ae03713b3d6b4f5bf82859f9c93be6ed.tar.gz |
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 <rory@netc.lu>
Diffstat (limited to 'src/poem/read.rs')
-rw-r--r-- | src/poem/read.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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); } |