Fix /open ranges by passing all URLs to open(1)

This is going to be incompatible with xdg-open since it takes only one
URL at a time. Write a wrapper script.
weechat-hashes
Curtis McEnroe 2018-08-12 23:44:58 -04:00
parent a09df5f697
commit 19464369c3
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 11 additions and 15 deletions

2
chat.h
View File

@ -141,7 +141,7 @@ void tabReject(void);
void urlScan(struct Tag tag, const char *str);
void urlList(struct Tag tag);
void urlOpen(struct Tag tag, size_t fromEnd);
void urlOpen(struct Tag tag, size_t at, size_t to);
void spawn(char *const argv[]);

11
input.c
View File

@ -90,14 +90,9 @@ static void inputUrl(struct Tag tag, char *params) {
urlList(tag);
}
static void inputOpen(struct Tag tag, char *params) {
if (!params) { urlOpen(tag, 1); return; }
size_t from = strtoul(strsep(&params, "-,"), NULL, 0);
if (!params) { urlOpen(tag, from); return; }
size_t to = strtoul(strsep(&params, "-,"), NULL, 0);
if (to < from) to = from;
for (size_t i = from; i <= to; ++i) {
urlOpen(tag, i);
}
size_t at = (params ? strtoul(strsep(&params, "-,"), NULL, 0) : 1);
size_t to = (params ? strtoul(params, NULL, 0) : at);
urlOpen(tag, at - 1, to);
}
static void inputView(struct Tag tag, char *params) {

13
url.c
View File

@ -72,14 +72,15 @@ void urlList(struct Tag tag) {
}
}
void urlOpen(struct Tag tag, size_t fromEnd) {
size_t count = 0;
void urlOpen(struct Tag tag, size_t at, size_t to) {
size_t argc = 1;
char *argv[2 + RING_LEN] = { "open" };
size_t tagIndex = 0;
for (size_t i = 0; i < RING_LEN; ++i) {
struct Entry entry = ring.buf[(ring.end - i) & (RING_LEN - 1)];
if (!entry.url || entry.tag != tag.id) continue;
if (++count != fromEnd) continue;
char *argv[] = { "open", entry.url, NULL };
spawn(argv);
return;
if (tagIndex >= at && tagIndex < to) argv[argc++] = entry.url;
tagIndex++;
}
if (argc > 1) spawn(argv);
}