]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added tfetch rule for ctags lookup
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 25 Jul 2017 13:21:17 +0000 (09:21 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 25 Jul 2017 13:21:17 +0000 (09:21 -0400)
tcmd
tfetch.c

diff --git a/tcmd b/tcmd
index ccf45c27642d5e4955e5e9259684ed0106fad4cc..79ffc7c7e45f173522ab694e20f0491c9d34df1a 100755 (executable)
--- a/tcmd
+++ b/tcmd
@@ -2,7 +2,7 @@
 
 # setup editor env
 export PS1=":; "
-export PATH="$HOME/.config/tide/tools:$PATH"
+export PATH="$HOME/.config/tide/tools:$HOME/bin:$PATH"
 export EDITRCFILE="$HOME/.config/edit/editrc"
 export BASH_ENV="$EDITRCFILE"
 export PROMPT_COMMAND='tide_cd "$PWD"'
index 86185eaedc37548eb11d11ccdc6d637233d1f87f..8f7a9c76fcac01040610eb9ec91cd2c781e3853f 100644 (file)
--- a/tfetch.c
+++ b/tfetch.c
@@ -5,6 +5,8 @@
 #include <unistd.h>
 #include <regex.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #ifdef __MACH__
     #define OPENCMD "open"
@@ -44,6 +46,12 @@ Rule* BuiltinRules[] = {
         { LAUNCH, "$EDITOR '$file'", NULL },
         { COMPLETE, NULL, NULL }
     },
+    (Rule[]){ // Look it up in ctags database
+        { ISFILE, "tags", NULL },
+        { EXEC, "grep -q '^$data' tags", NULL },
+        { LAUNCH, "tide `picktag fetch tags '$data'`", NULL },
+        { COMPLETE, NULL, NULL }
+    },
     (Rule[]){ // If it's an existing directory, open it with system default
         { ISDIR, "$data", NULL },
         { LAUNCH, OPENCMD " $data", NULL },
@@ -212,12 +220,15 @@ int main(int argc, char** argv) {
     if (argc != 2) usage(argv[0]);
     setenv("data", argv[1], 1);
     for (int i = 0; i < nelem(BuiltinRules); i++) {
-        for (Rule* rule = BuiltinRules[i]; true; rule++) {
+        Rule* rule = BuiltinRules[i];
+        for (; rule->type != COMPLETE; rule++) {
             //printf("%d '%s' '%s'\n", rule->type, rule->arg1, rule->arg2);
             if (!apply_rule(rule))
                 break;
         }
         //puts("");
+        if (rule->type == COMPLETE)
+            exit(0);
     }
     return 1;
 }