summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-08 21:21:21 -0500
committerJune McEnroe <june@causal.agency>2020-02-08 21:21:21 -0500
commit2db17e83a914586fd351437ac5323713f1e66478 (patch)
tree4716c982f38bd57a1f5636c1606e894912b538ff
parentSet FDs CLOEXEC (diff)
downloadcatgirl-2db17e83a914586fd351437ac5323713f1e66478.tar.gz
catgirl-2db17e83a914586fd351437ac5323713f1e66478.zip
Allow overriding the /open utility
Diffstat (limited to '')
-rw-r--r--catgirl.18
-rw-r--r--chat.c4
-rw-r--r--chat.h1
-rw-r--r--url.c14
4 files changed, 22 insertions, 5 deletions
diff --git a/catgirl.1 b/catgirl.1
index f489d07..6129b71 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -9,6 +9,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl ev
+.Op Fl O Ar open
 .Op Fl a Ar auth
 .Op Fl c Ar cert
 .Op Fl h Ar host
@@ -46,6 +47,13 @@ following their corresponding flags.
 .Pp
 The arguments are as follows:
 .Bl -tag -width Ds
+.It Fl O Ar util , Cm open = Ar util
+Set the command used by
+.Ic /open .
+The default is the first available of
+.Xr open 1 ,
+.Xr xdg-open 1 .
+.
 .It Fl a Ar user Ns : Ns Ar pass , Cm sasl-plain = Ar user Ns : Ns Ar pass
 Authenticate as
 .Ar user
diff --git a/chat.c b/chat.c
index c0c2d28..77aa61d 100644
--- a/chat.c
+++ b/chat.c
@@ -81,9 +81,10 @@ int main(int argc, char *argv[]) {
 	const char *user = NULL;
 	const char *real = NULL;
 
-	const char *Opts = "!a:c:eh:j:k:n:p:r:u:vw:";
+	const char *Opts = "!O:a:c:eh:j:k:n:p:r:u:vw:";
 	const struct option LongOpts[] = {
 		{ "insecure", no_argument, NULL, '!' },
+		{ "open", required_argument, NULL, 'O' },
 		{ "sasl-plain", required_argument, NULL, 'a' },
 		{ "cert", required_argument, NULL, 'c' },
 		{ "sasl-external", no_argument, NULL, 'e' },
@@ -103,6 +104,7 @@ int main(int argc, char *argv[]) {
 	while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
 		switch (opt) {
 			break; case '!': insecure = true;
+			break; case 'O': urlOpenUtil = optarg;
 			break; case 'a': sasl = true; self.plain = optarg;
 			break; case 'c': cert = optarg;
 			break; case 'e': sasl = true;
diff --git a/chat.h b/chat.h
index 583107a..3084359 100644
--- a/chat.h
+++ b/chat.h
@@ -169,6 +169,7 @@ void completeClear(size_t id);
 size_t completeID(const char *str);
 enum Color completeColor(size_t id, const char *str);
 
+extern const char *urlOpenUtil;
 void urlScan(size_t id, const char *nick, const char *mesg);
 void urlOpenCount(size_t id, size_t count);
 void urlOpenMatch(size_t id, const char *str);
diff --git a/url.c b/url.c
index 1396765..c9c4d5c 100644
--- a/url.c
+++ b/url.c
@@ -95,7 +95,8 @@ void urlScan(size_t id, const char *nick, const char *mesg) {
 	}
 }
 
-static const char *OpenBins[] = { "open", "xdg-open" };
+const char *urlOpenUtil;
+static const char *OpenUtils[] = { "open", "xdg-open" };
 
 static void urlOpen(const char *url) {
 	pid_t pid = fork();
@@ -105,10 +106,15 @@ static void urlOpen(const char *url) {
 	close(STDIN_FILENO);
 	dup2(procPipe[1], STDOUT_FILENO);
 	dup2(procPipe[1], STDERR_FILENO);
-	for (size_t i = 0; i < ARRAY_LEN(OpenBins); ++i) {
-		execlp(OpenBins[i], OpenBins[i], url, NULL);
+	if (urlOpenUtil) {
+		execlp(urlOpenUtil, urlOpenUtil, url, NULL);
+		warn("%s", urlOpenUtil);
+		_exit(EX_CONFIG);
+	}
+	for (size_t i = 0; i < ARRAY_LEN(OpenUtils); ++i) {
+		execlp(OpenUtils[i], OpenUtils[i], url, NULL);
 		if (errno != ENOENT) {
-			warn("%s", OpenBins[i]);
+			warn("%s", OpenUtils[i]);
 			_exit(EX_CONFIG);
 		}
 	}
r> 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe