From 78c0e874fba3c13178f1829704a32ef9a653d6c5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 25 Jul 2017 09:21:17 -0400 Subject: [PATCH] Added tfetch rule for ctags lookup --- tcmd | 2 +- tfetch.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tcmd b/tcmd index ccf45c2..79ffc7c 100755 --- 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"' diff --git a/tfetch.c b/tfetch.c index 86185ea..8f7a9c7 100644 --- a/tfetch.c +++ b/tfetch.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #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; } -- 2.49.0