From 4274d7daaea5bc33e171220337848ae9eddbb4f1 Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Tue, 15 Jan 2019 01:03:14 +0000 Subject: [PATCH] add g!sig command --- mux.go | 4 +++- x/mux/man.go | 29 ++++++++++++++++++++++++++++- x/mux/man/sig | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100755 x/mux/man/sig diff --git a/mux.go b/mux.go index 933f1da2ba37bdc86c9baabd465bce9676733c53..f22afdc654d313fa4761804d4b4a627bafa3fc0d 100644 --- a/mux.go +++ b/mux.go @@ -28,7 +28,9 @@ func init() { Router.Route("lookman", "Search for a string in the Plan 9 manual pages (From 9front for now).", Router.Lookman) - Router.Route("fortune", "Display fortunes. Bonus files are (theo troll rsc terry rob ken).", Router.Fortunes) + Router.Route("sig", "Search for function definitions in the Plan 9 manual pages (From 9front for now).", Router.Sig) + + Router.Route("fortune", "Display fortunes. Bonus files are (theo troll rsc terry rob ken henesy).", Router.Fortunes) Router.Route("bullshit", "Print logical statements with sound grounding.", Router.Bullshit) diff --git a/x/mux/man.go b/x/mux/man.go index 43b83350a68644f535e664a00b1864274ba72cdf..fe35f2fa8311c1e72551396de9fe6fd3680792ac 100644 --- a/x/mux/man.go +++ b/x/mux/man.go @@ -111,8 +111,35 @@ func (m *Mux) Man(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { } // Fetch a summary of a man page -func (m *Mux) Summary(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { +func (m *Mux) Sig(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) { + resp := "\n```" + if !(len(ctx.Fields) >= 2) { + resp += "Usage: lookman key ...\n" + } else { + // g!sig vmx + args := ctx.Fields[1:] + + // rc or get out + out, err := exec.Command("./x/mux/man/sig", args...).Output() + if err != nil { + resp += "No sig script found." + goto END + } else { + if len(out) < 2 { + resp += "No matching definitions found." + goto END + } + + str := string(out) + // lines := strings.Split(str, "\n") + resp += str + } + } + + END: + resp += "```\n" + ds.ChannelMessageSend(dm.ChannelID, resp) } // Call lookman on a given query diff --git a/x/mux/man/sig b/x/mux/man/sig new file mode 100755 index 0000000000000000000000000000000000000000..68a8b1b531f9a4a0a532abf86f17e7f9568fec0f --- /dev/null +++ b/x/mux/man/sig @@ -0,0 +1,30 @@ +#!/usr/bin/env rc +# Usage: sig key ... +# prints out function signatures by grepping the manual + +MIRROR = /usr/share/mirror/plan9front +*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_ \012'} # fold case, delete funny chars +if(~ $#* 0){ + echo Usage: sig function ... + exit 1 +} + +for (i) { + files=`{9 grep -il '[ ]\*?'$i'\(' $MIRROR/sys/man/2/*} + for(j in $files) { + {echo .nr LL 20i; 9 sed -n '/^.SH SYNOPSIS/,/^.SH.*DESCR/p' $j } | + 9 nroff -man | + sed ' + :a + /,$/ { + N + s/\n// + } + ta + s/[ ]+/ /g' | + 9 grep -i -e '[ *]'$i'\(' | sed 's/^[ +]/ /' | sed 's/ //g' + } +} + +exit 0 +