From e92f76773cb8d24ac8349cb230928a3922f2ab12 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 2 Nov 2019 23:03:48 -0400 Subject: [PATCH] added ability to pull fetch rules from ~/config/ --- src/fetch.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/fetch.c b/src/fetch.c index c8f4050..bfa4492 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -3,6 +3,7 @@ #include #include #include +#include typedef struct { enum { @@ -63,9 +64,34 @@ static Rule*** BuiltinRules = (Rule**[]){ &(Rule){ LAUNCH, "cd $data && ls -ap | tide -", NULL }, &(Rule){ COMPLETE, NULL, NULL } }, + (Rule*[]){ /* look for files in /usr/include */ + &(Rule){ ISFILE, "/usr/include/$data", NULL }, + &(Rule){ LAUNCH, "edit \"/usr/include/$data\"", NULL }, + &(Rule){ COMPLETE, NULL, NULL } + }, + (Rule*[]){ /* look for files in /usr/local/include */ + &(Rule){ ISFILE, "/usr/local/include/$data", NULL }, + &(Rule){ LAUNCH, "edit \"/usr/local/include/$data\"", NULL }, + &(Rule){ COMPLETE, NULL, NULL } + }, + (Rule*[]){ /* look for files in /usr/X11/include */ + &(Rule){ ISFILE, "/usr/X11/include/$data", NULL }, + &(Rule){ LAUNCH, "edit \"/usr/X11/include/$data\"", NULL }, + &(Rule){ COMPLETE, NULL, NULL } + }, NULL }; +static char* homedir_path(char* rpath) +{ + static char path[8192] = {0}; + if (!path[0]) + { + snprintf(path, sizeof(path)-1,"%s/%s", getpwuid(getuid())->pw_dir, rpath); + } + return path; +} + /******************************************************************************/ @@ -417,7 +443,7 @@ void parse_rules(char* path) { add_ruleset(rules, nrules, calloc(1, sizeof(Rule))); } - add_ruleset(NULL, 0, NULL); +// add_ruleset(NULL, 0, NULL); } telem_send("DONE\n", path); } @@ -455,6 +481,8 @@ int main(int argc, char** argv) { /* load rules from files */ parse_rules("fetch.rules"); + parse_rules(homedir_path("config/tide/fetch.rules")); + add_ruleset(NULL, 0, NULL); telem_send("FETCH(%s)\n", argv[1]); setenv("data", argv[1], 1); -- 2.52.0