From 3232901c14ba7197fbc464cd9eaf40bddaa4efbb Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 29 Dec 2024 12:43:39 +0100 Subject: [PATCH] ENH: Auto-detect sed in-place editing capability during "make install" We're already preprocessing the default configuration; it's easy to add another sed invocation to uncomment the TODOTXT_SED_COMMAND definition. And since we're using in-place editing here, the sed command will only succeed if it has that capability. In other words, it's both the capability detection and the corresponding config adaptation in one command! The config.bak file is cleaned up on success (a backup-less -i could be used, but as todo.sh uses the backup file variant and there might be sed commands that support one but not the other, it's safer this way). Both outcomes (emulation required or not) are logged as well. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 64812bfe..dda5c4f3 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,12 @@ install: build installdirs ## local package install $(INSTALL_DATA) $(DISTNAME)/todo_completion $(DEST_COMPLETION) if [ ! -e $(DEST_CONFIG) ]; then \ sed 's@^\(export TODO_DIR=\).*@\1~/.todo@' $(DISTNAME)/todo.cfg > $(DEST_CONFIG); \ + if sed -i.bak 's@^# \(export TODOTXT_SED_COMMAND=sed\)$$@\1@' $(DEST_CONFIG) 2>/dev/null; then \ + rm -f $(DEST_CONFIG).bak; \ + echo 'This sed supports in-place editing.'; \ + else \ + echo 'Need sed in-place emulation here.'; \ + fi; \ fi .PHONY: uninstall