From 2bdeb6aad95688e583347de710abec2ddd67764a Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Tue, 2 Aug 2022 03:04:51 +0500 Subject: [PATCH] Use ctpvquit instead of cmd on-quit cmd on-quit is not available in the latest lf release (r27) --- Makefile | 9 +++++++-- README.md | 7 +------ doc/ctpv.1 | 2 +- quit/Makefile | 6 ++++++ quit/ctpvquit.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 quit/Makefile create mode 100644 quit/ctpvquit.c diff --git a/Makefile b/Makefile index b2aa3de..1c33628 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ options: install: install.bin install.man -install.bin: ctpv ctpvclear +install.bin: ctpv quit/ctpvquit ctpvclear $(INSTALL) -d $(BINPREFIX) $(INSTALL) $^ $(BINPREFIX) @@ -34,11 +34,13 @@ install.man: doc/ctpv.1 $(INSTALL) -m 0644 $^ $(MANPREFIX) uninstall: - $(RM) $(BINPREFIX)/ctpv $(BINPREFIX)/ctpvclear $(MANPREFIX)/ctpv.1 + $(RM) $(BINPREFIX)/ctpv $(BINPREFIX)/ctpvclear $(BINPREFIX)/ctpvquit \ + $(MANPREFIX)/ctpv.1 clean: $(RM) ctpv $(OBJ) $(DEP) $(GEN) $(MAKE) -C embed clean + $(MAKE) -C quit clean docs: README.md doc/ctpv.1 deptable/list.awk $(PRE) | deptable/markdown.sed | deptable/insert.awk README.md @@ -70,6 +72,9 @@ gen: embed/embed: .force $(MAKE) -C embed +quit/ctpvquit: .force + $(MAKE) -C quit + -include $(DEP) .PHONY: all options install install.bin install.man uninstall \ diff --git a/README.md b/README.md index b6defb5..ead1200 100644 --- a/README.md +++ b/README.md @@ -96,16 +96,11 @@ yay -S ctpv-git Add these lines to your lf config (usually located at `~/.config/lf/lfrc`). -Note: `on-quit` command is not a part of -[lf r27 release](https://github.com/gokcehan/lf/releases/tag/r27) -yet, so I strongly suggest you to install the latest version [from the GitHub page][lf] -(or [`lf-git`](https://aur.archlinux.org/packages/lf-git) AUR package if you use Arch Linux). - ``` set previewer ctpv set cleaner ctpvclear &ctpv -s $id -cmd on-quit $ctpv -e $id +&ctpvquit $id ``` ## Documentation diff --git a/doc/ctpv.1 b/doc/ctpv.1 index 526ce1c..0a5907e 100644 --- a/doc/ctpv.1 +++ b/doc/ctpv.1 @@ -145,7 +145,7 @@ configuration file (usually located at set previewer ctpv set cleaner ctpvclear &ctpv -s $id -cmd on-quit $ctpv -e $id +&ctpvquit $id .EE .RE . diff --git a/quit/Makefile b/quit/Makefile new file mode 100644 index 0000000..906c976 --- /dev/null +++ b/quit/Makefile @@ -0,0 +1,6 @@ +ctpvquit: ctpvquit.c + +clean: + $(RM) ctpvquit + +.PHONY: clean diff --git a/quit/ctpvquit.c b/quit/ctpvquit.c new file mode 100644 index 0000000..97d7123 --- /dev/null +++ b/quit/ctpvquit.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include + +int main (int argc, char *argv[]) +{ + if (argc <= 1) { + fprintf(stderr, "id not given\n"); + return EXIT_FAILURE; + } + + char *pid_s = argv[1]; + + char *endptr; + + errno = 0; + long pid = strtol(pid_s, &endptr, 10); + + if (errno != 0) { + perror("strtol"); + return EXIT_FAILURE; + } + + if (endptr == pid_s) { + fprintf(stderr, "%s: invalid number\n", pid_s); + return EXIT_FAILURE; + } + + while (1) { + sleep(5); + + if (kill(pid, 0) == -1) { + if (errno != ESRCH) { + perror("kill"); + return EXIT_FAILURE; + } + + execlp("ctpv", "ctpv", "-e", pid_s, NULL); + perror("execlp"); + break; + } + } + + return EXIT_FAILURE; +}