Allow overriding the /open utility

weechat-hashes
C. McEnroe 2020-02-08 21:21:21 -05:00
parent 362d779b61
commit 2db17e83a9
4 changed files with 22 additions and 5 deletions

View File

@ -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

4
chat.c
View File

@ -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;

1
chat.h
View File

@ -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);

14
url.c
View File

@ -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);
}
}