]> granicus.if.org Git - neomutt/commitdiff
Introduce MUTT_TOKEN_BACKTICK_VARS to expand variables within backticks
authorPietro Cerutti <gahr@gahr.ch>
Mon, 7 May 2018 13:52:55 +0000 (13:52 +0000)
committerRichard Russon <rich@flatcap.org>
Tue, 15 May 2018 16:41:35 +0000 (17:41 +0100)
This is a new flag to mutt_extract_token which triggers variable
expansion within backticks.

With this flag:

```
:set my_foo="`echo foo $pager bar`"
:set ?my_foo
foo builtin bar
```

Without this flag:

```
:set my_foo="`echo foo $pager bar`"
:set ?my_foo
foo  bar
```

This flag is currently only passed when parsing a `set` command.

init.c
mutt.h

diff --git a/init.c b/init.c
index 1e6bceef35593910790c3deefeffa5054a232ed7..4cf597444f90869586b78e1f236bce7d81848bb9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -620,7 +620,15 @@ int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
       struct Buffer cmd;
       mutt_buffer_init(&cmd);
       *pc = '\0';
-      mutt_extract_token(&cmd, tok, MUTT_TOKEN_QUOTE | MUTT_TOKEN_SPACE);
+      if (flags & MUTT_TOKEN_BACKTICK_VARS)
+      {
+          /* recursively extract tokens to interpolate variables */
+          mutt_extract_token(&cmd, tok, MUTT_TOKEN_QUOTE | MUTT_TOKEN_SPACE);
+      }
+      else
+      {
+          cmd.data = mutt_str_strdup(tok->dptr);
+      }
       *pc = '`';
       pid = mutt_create_filter(cmd.data, NULL, &fp, NULL);
       if (pid < 0)
@@ -2492,7 +2500,7 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
           myvar = mutt_str_strdup(myvar);
         }
 
-        mutt_extract_token(buf, s, 0);
+        mutt_extract_token(buf, s, MUTT_TOKEN_BACKTICK_VARS);
 
         if (myvar)
         {
diff --git a/mutt.h b/mutt.h
index d550ec3614738bc595d3bf333293740830e04285..d555bb46b1fa77f69ebae31b53e73e09799c17d5 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -70,13 +70,14 @@ struct Mapping;
 #endif
 
 /* flags for mutt_get_token() */
-#define MUTT_TOKEN_EQUAL      1       /* treat '=' as a special */
-#define MUTT_TOKEN_CONDENSE   (1<<1)  /* ^(char) to control chars (macros) */
-#define MUTT_TOKEN_SPACE      (1<<2)  /* don't treat whitespace as a term */
-#define MUTT_TOKEN_QUOTE      (1<<3)  /* don't interpret quotes */
-#define MUTT_TOKEN_PATTERN    (1<<4)  /* !)|~ are terms (for patterns) */
-#define MUTT_TOKEN_COMMENT    (1<<5)  /* don't reap comments */
-#define MUTT_TOKEN_SEMICOLON  (1<<6)  /* don't treat ; as special */
+#define MUTT_TOKEN_EQUAL         (1<<0)  /* treat '=' as a special */
+#define MUTT_TOKEN_CONDENSE      (1<<1)  /* ^(char) to control chars (macros) */
+#define MUTT_TOKEN_SPACE         (1<<2)  /* don't treat whitespace as a term */
+#define MUTT_TOKEN_QUOTE         (1<<3)  /* don't interpret quotes */
+#define MUTT_TOKEN_PATTERN       (1<<4)  /* !)|~ are terms (for patterns) */
+#define MUTT_TOKEN_COMMENT       (1<<5)  /* don't reap comments */
+#define MUTT_TOKEN_SEMICOLON     (1<<6)  /* don't treat ; as special */
+#define MUTT_TOKEN_BACKTICK_VARS (1<<7)  /* expand variables within backticks */
 
 /* types for mutt_add_hook() */
 #define MUTT_FOLDERHOOK   (1 << 0)