From: Michael D. Lowis Date: Mon, 17 Dec 2018 16:07:12 +0000 (-0500) Subject: had to keep the eval function for rule actions that do not utilize the shell but... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=dc7f52b9d2378dac6a80efcf7d3a498b865a0170;p=projs%2Ftide.git had to keep the eval function for rule actions that do not utilize the shell but at least shell commands now dont have the weird and confusing double eval behavior --- diff --git a/TODO.md b/TODO.md index 4f72d7e..3183fed 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ ## STAGING * registrar doesnt match open windows when new file created and is then opened for edit or line number -* fetch should stuff match strings in environment variables instead of evaling * implement a mini-sed command to standardize scripts across platforms without relying on sed * registrar should remove invalid windows from registry when detected * tide should re-register with the registrar when a new registrar is launched diff --git a/config.h b/config.h index 65c73f2..543597d 100644 --- a/config.h +++ b/config.h @@ -75,7 +75,6 @@ static int Palette[ClrCount] = { [ScrollFg] = 0xF0F0E5, /* Scroll region foreground */ [VerBdr] = 0x909047, /* Vertical border */ [HorBdr] = 0x000000, /* Horizontal border */ - }; #ifdef FETCH_RULES @@ -90,13 +89,13 @@ Rule* BuiltinRules[] = { (Rule[]){ /* Match URLS and open them with the browser */ { ISSET, "BROWSER", NULL }, { MATCHES, "data", "^(https?|ftp)://.*" }, - { LAUNCH, "$BROWSER \"$0\"", NULL }, + { LAUNCH, "$BROWSER \"$M0\"", NULL }, { COMPLETE, NULL, NULL } }, (Rule[]){ /* Open files with addresses in the editor */ { MATCHES, "data", "^([^:]+):([0-9]+)" }, - { ISFILE, "$1", NULL }, - { LAUNCH, "edit \"$0\"", NULL }, + { ISFILE, "$M1", NULL }, + { LAUNCH, "edit \"$M0\"", NULL }, { COMPLETE, NULL, NULL } }, (Rule[]){ /* If it's an existing text file, open it with editor */ diff --git a/src/fetch.c b/src/fetch.c index 817dde2..19e21cc 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -25,10 +25,7 @@ char* Matches[10]; /******************************************************************************/ char* getvar(char* val) { - if (strlen(val) == 1 && isdigit(*val)) - val = Matches[*val - '0']; - else - val = getenv(val); + val = getenv(val); return (val ? val : ""); } @@ -71,10 +68,11 @@ bool matches(char* var, char* patt) { regmatch_t matches[10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}; if (regcomp(®ex, patt, REG_EXTENDED) == 0) { var = getvar(var); - memset(Matches, 0, sizeof(Matches)); int err = regexec(®ex, var, nelem(matches), matches, 0); for (int i = 0; i < 10 && matches[i].rm_so >= 0; i++) { - Matches[i] = strndup(var+matches[i].rm_so, matches[i].rm_eo-matches[i].rm_so); + char* matchval = strndup(var+matches[i].rm_so, matches[i].rm_eo-matches[i].rm_so); + setenv((char[]){ 'M', ('0' + i), 0 }, matchval, 1); + free(matchval); } return (err == 0); } @@ -129,9 +127,8 @@ bool find_file(char* file) { } void runcmd(char* cmd) { - char* shellcmd[] = { getvar("SHELL"), "-c", NULL, NULL }; + char* shellcmd[] = { getvar("SHELL"), "-c", cmd, NULL }; if (!shellcmd[0]) shellcmd[0] = "/bin/sh"; - shellcmd[2] = eval(cmd); _exit(execvp(shellcmd[0], shellcmd)); }