blob: cec27064e1929da61367fa32dc1e2a494f442bfe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
From caaee2d787622fb680ef640b8ebda4678bbebdd3 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
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
|