From caaee2d787622fb680ef640b8ebda4678bbebdd3 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Fri, 26 Dec 2014 13:27:13 +0200 Subject: [PATCH 19/19] Shellvars: allow command-specific environment variables --- lenses/shellvars.aug | 5 +++-- lenses/tests/test_shellvars.aug | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug index 5a48f11..5a6d510 100644 --- a/lenses/shellvars.aug +++ b/lenses/shellvars.aug @@ -149,7 +149,8 @@ module Shellvars = (* Command *) let rec command = - let reserved_key = /exit|shift|return|ulimit|unset|export|source|\.|if|for|select|while|until|then|else|fi|done|case|eval|alias/ + let env = [ key key_re . eq . store anyquot . Sep.cl_or_space ] + in let reserved_key = /exit|shift|return|ulimit|unset|export|source|\.|if|for|select|while|until|then|else|fi|done|case|eval|alias/ in let word = /[A-Za-z0-9_.-\/]+/ in let entry_eol = entry_eol_nocommand | entry_eol_item command in let entry_noeol = entry_noeol_nocommand | entry_item command @@ -157,7 +158,7 @@ module Shellvars = in let pipe = action_pipe (entry_eol_item command | entry_item command) in let and = action_and entry in let or = action_or entry - in Util.indent . label "@command" . store (word - reserved_key) + in Util.indent . label "@command" . env* . store (word - reserved_key) . [ Sep.cl_or_space . label "@arg" . sto_to_semicol]? . ( pipe | and | or )? diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug index 544226e..673fc0d 100644 --- a/lenses/tests/test_shellvars.aug +++ b/lenses/tests/test_shellvars.aug @@ -672,6 +672,13 @@ test Shellvars.lns get "cat /etc/issue | grep -q \"Debian\" && echo moo || echo { "@command" = "echo" { "@arg" = "baa" } } } } } } } } +(* Command-specific environment variables *) +test Shellvars.lns get "abc=def \\\n ghi=\"jkl mno\" command arg1 arg2\n" = + { "@command" = "command" + { "abc" = "def" } + { "ghi" = "\"jkl mno\"" } + { "@arg" = "arg1 arg2" } + } (* Wrapped command sequences *) -- 2.5.0