summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-01-10 18:35:04 +0100
committerCanop <cano.petrole@gmail.com>2020-01-10 18:35:04 +0100
commit4d34f965e11315759427b502807c5fb8395d0168 (patch)
treea9f4c55f088bff9b9a3b9b9616edce102b2ecf93
parent37a9a5e3bbb4841db8b2c994b66e1012a0bb21c9 (diff)
allow env vars used in verb execution to contain parameters
fix #114 More precisely when a token of the execution string is resolved as an env variable, the value is splited by space. I hope there's no usage broken by this when the env variable is used as another token that the first one...
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/external.rs23
2 files changed, 16 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e1976a4..0a45f05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
- backspace was previously bind to back if not consumed by input. This is removed
- fix unsignificative events interpreted as previous event repetition
- fix wrong background applied below sizes
+- allow env vars used in verb execution to contain parameters (fix #114)
<a name="v0.11.5"></a>
### v0.11.5 - 2020-01-10
diff --git a/src/external.rs b/src/external.rs
index eef920a..495fcc5 100644
--- a/src/external.rs
+++ b/src/external.rs
@@ -44,13 +44,20 @@ pub enum Launchable {
},
}
-/// If s starts by a '$', replace it by the environment variable of the same name
-fn resolve_env_variable(s: String) -> String {
- if s.starts_with('$') {
- env::var(&s[1..]).unwrap_or(s)
- } else {
- s
+/// If a part starts by a '$', replace it by the environment variable of the same name.
+/// This part is splitted too (because of https://github.com/Canop/broot/issues/114)
+fn resolve_env_variables(parts: Vec<String>) -> Vec<String> {
+ let mut resolved = Vec::new();
+ for part in parts.into_iter() {
+ if part.starts_with('$') {
+ if let Ok(val) = env::var(&part[1..]) {
+ resolved.extend(val.split(' ').map(|s|s.to_string()));
+ continue;
+ }
+ }
+ resolved.push(part);
}
+ resolved
}
impl Launchable {
@@ -78,8 +85,8 @@ impl Launchable {
}
}
- pub fn program(mut parts: Vec<String>) -> io::Result<Launchable> {
- let mut parts = parts.drain(0..).map(resolve_env_variable);
+ pub fn program(parts: Vec<String>) -> io::Result<Launchable> {
+ let mut parts = resolve_env_variables(parts).into_iter();
match parts.next() {
Some(exe) => Ok(Launchable::Program {
exe,