summary refs log tree commit diff
path: root/command.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-09 14:09:27 -0500
committerJune McEnroe <june@causal.agency>2020-02-09 14:09:27 -0500
commit5254e1035c5945407ee354276f839426fc17e432 (patch)
tree3dcbba594340dd4f5fd72bac0cced834fd9db1b9 /command.c
parentAdd M-u (diff)
downloadcatgirl-5254e1035c5945407ee354276f839426fc17e432.tar.gz
catgirl-5254e1035c5945407ee354276f839426fc17e432.zip
Add /help
Now with automatic search! Also had to fix the SIGCHLD handling...
Diffstat (limited to '')
-rw-r--r--command.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/command.c b/command.c
index f88a6d5..44d0d54 100644
--- a/command.c
+++ b/command.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "chat.h"
 
@@ -158,6 +159,23 @@ static void commandCopy(size_t id, char *params) {
 	urlCopyMatch(id, params);
 }
 
+static void commandHelp(size_t id, char *params) {
+	(void)id;
+	uiHide();
+
+	pid_t pid = fork();
+	if (pid < 0) err(EX_OSERR, "fork");
+	if (pid) return;
+
+	char buf[256];
+	snprintf(buf, sizeof(buf), "ip%s$", (params ? params : "COMMANDS"));
+	setenv("LESS", buf, 1);
+	execlp("man", "man", "1", "catgirl", NULL);
+	dup2(procPipe[1], STDERR_FILENO);
+	warn("man");
+	_exit(EX_UNAVAILABLE);
+}
+
 static const struct Handler {
 	const char *cmd;
 	Command *fn;
@@ -165,6 +183,7 @@ static const struct Handler {
 	{ "/close", commandClose },
 	{ "/copy", commandCopy },
 	{ "/debug", commandDebug },
+	{ "/help", commandHelp },
 	{ "/join", commandJoin },
 	{ "/me", commandMe },
 	{ "/names", commandNames },