]> git.mdlowis.com Git - projs/tide.git/commitdiff
added ability to pull fetch rules from ~/config/
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 3 Nov 2019 03:03:48 +0000 (23:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 3 Nov 2019 03:03:48 +0000 (23:03 -0400)
src/fetch.c

index c8f4050aa5d587b68f55e5fd9700a1b3c4217212..bfa44925317b034cce36b63e6dc8219d47401de3 100644 (file)
@@ -3,6 +3,7 @@
 #include <regex.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <pwd.h>
 
 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);