From: Pietro Cerutti Date: Mon, 7 May 2018 13:52:55 +0000 (+0000) Subject: Introduce MUTT_TOKEN_BACKTICK_VARS to expand variables within backticks X-Git-Tag: neomutt-20180622~56 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0597b6375971ca1d3f610fbcc83dd7f1f4e770ca;p=neomutt Introduce MUTT_TOKEN_BACKTICK_VARS to expand variables within backticks 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. --- diff --git a/init.c b/init.c index 1e6bceef3..4cf597444 100644 --- 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 d550ec361..d555bb46b 100644 --- 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)