Skip to content

Commit

Permalink
ENH: Auto-detect sed in-place editing capability during "make install"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
inkarkat committed Dec 29, 2024
1 parent e84a78e commit 3232901
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3232901

Please sign in to comment.