commit 88398ed1fd8f071a8d31bd64d2e93159f53b559c
parent e96335b4155a2bac0e9e2c1ac53ec8735730cbe7
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 7 Aug 2020 15:13:25 +0200
add $SFEED_YANKER to make xclip an optional dependency and configurable at run-time
Change pipeitem() a bit to pipe a specified field and not need "cut".
Update and tweak the README.
Diffstat:
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/README b/README
@@ -59,9 +59,17 @@ Run-time dependencies
- A (POSIX) shell.
- A terminal (emulator) supporting UTF-8 and the used capabilities.
-- xclip for yanking the url or enclosure: can be changed easily.
-- awk, used by the sfeed_content and sfeed_markread script (optional).
-- lynx, used by the sfeed_content script (optional).
+
+
+Optional run-time dependencies
+------------------------------
+
+- xclip for yanking the url or enclosure. See $SFEED_YANKER to change it.
+- xdg-open, used as a plumber by default. See $SFEED_PLUMBER to change it.
+- awk, used by the sfeed_content and sfeed_markread script.
+ See the ENVIRONMENT VARIABLES section in the man page to change it.
+- lynx, used by the sfeed_content script to convert HTML content.
+ See the ENVIRONMENT VARIABLES section in the man page to change it.
OS tested
diff --git a/sfeed_curses.1 b/sfeed_curses.1
@@ -1,4 +1,4 @@
-.Dd August 2, 2020
+.Dd August 7, 2020
.Dt SFEED_CURSES 1
.Os
.Sh NAME
@@ -91,10 +91,12 @@ The line is piped to the program specified in
.Ev SFEED_PIPER .
.It y
Pipe the TAB-Separated Value for yanking the url.
-The used command to yank the url is "cut -f 3 | xclip -r".
+The line is piped to the program specified in
+.Ev SFEED_YANKER .
.It E
Pipe the TAB-Separated Value for yanking the enclosure.
-The used command to yank the enclosure is "cut -f 8 | xclip -r".
+The line is piped to the program specified in
+.Ev SFEED_YANKER .
.It r
Mark item as read.
This will only work when
@@ -169,6 +171,10 @@ is also set, if unset the program used is "sfeed_markread unread".
The marked items are piped to the program.
The program is expected to merge items in a safe/transactional manner.
The program should return the exit status 0 on succeed or non-zero on failure.
+.It Ev SFEED_YANKER
+A program where the url or enclosure is piped to for yanking it to the
+clipboard.
+By default this is "xclip -r".
.It Ev SFEED_FEED_PATH
This variable is set by
.Nm
diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -45,6 +45,7 @@
static char *plumber = "xdg-open"; /* environment variable: $SFEED_PLUMBER */
static char *piper = "sfeed_content"; /* environment variable: $SFEED_PIPER */
+static char *yanker = "xclip -r"; /* environment variable: $SFEED_YANKER */
enum {
ATTR_RESET = 0, ATTR_BOLD_ON = 1, ATTR_FAINT_ON = 2, ATTR_REVERSE_ON = 7
@@ -543,11 +544,12 @@ init(void)
needcleanup = 1;
}
-/* pipe item to a program, if `wantoutput` is set then cleanup and restore the
- terminal attribute settings, if not set then don't do that and also ignore
- stdout and stderr. */
+/* pipe item line or item field to a program.
+ If `field` is -1 then pipe the TSV line, else a specified field.
+ if `wantoutput` is 1 then cleanup and restore the tty,
+ if 0 then don't do that and also write stdout and stderr to /dev/null. */
void
-pipeitem(const char *cmd, struct item *item, int wantoutput)
+pipeitem(const char *cmd, struct item *item, int field, int wantoutput)
{
FILE *fp;
int i, pid, wpid, status;
@@ -567,10 +569,14 @@ pipeitem(const char *cmd, struct item *item, int wantoutput)
errno = 0;
if (!(fp = popen(cmd, "w")))
err(1, "popen");
- for (i = 0; i < FieldLast; i++) {
- if (i)
- fputc('\t', fp);
- fputs(item->fields[i], fp);
+ if (field == -1) {
+ for (i = 0; i < FieldLast; i++) {
+ if (i)
+ fputc('\t', fp);
+ fputs(item->fields[i], fp);
+ }
+ } else {
+ fputs(item->fields[field], fp);
}
fputc('\n', fp);
status = pclose(fp);
@@ -1449,7 +1455,7 @@ mousereport(int button, int release, int x, int y)
row = pane_row_get(p, p->pos);
item = (struct item *)row->data;
markread(p, p->pos, p->pos, 1);
- pipeitem(piper, item, 1);
+ pipeitem(piper, item, -1, 1);
}
break;
case 3: /* scroll up */
@@ -1686,6 +1692,8 @@ main(int argc, char *argv[])
plumber = tmp;
if ((tmp = getenv("SFEED_PIPER")))
piper = tmp;
+ if ((tmp = getenv("SFEED_YANKER")))
+ yanker = tmp;
urlfile = getenv("SFEED_URL_FILE");
panes[PaneFeeds].row_format = feed_row_format;
@@ -1933,18 +1941,18 @@ nextpage:
case 'c': /* items: pipe TSV line to program */
case 'p':
case '|':
- case 'y': /* yank: pipe TSV line to yank url to clipboard */
- case 'E': /* yank: pipe TSV line to yank enclosure to clipboard */
+ case 'y': /* yank: pipe TSV field to yank url to clipboard */
+ case 'E': /* yank: pipe TSV field to yank enclosure to clipboard */
if (selpane == PaneItems && panes[selpane].nrows) {
p = &panes[selpane];
row = pane_row_get(p, p->pos);
item = (struct item *)row->data;
switch (ch) {
- case 'y': pipeitem("cut -f 3 | xclip -r", item, 0); break;
- case 'E': pipeitem("cut -f 8 | xclip -r", item, 0); break;
+ case 'y': pipeitem(yanker, item, FieldLink, 0); break;
+ case 'E': pipeitem(yanker, item, FieldEnclosure, 0); break;
default:
markread(p, p->pos, p->pos, 1);
- pipeitem(piper, item, 1);
+ pipeitem(piper, item, -1, 1);
break;
}
}