Skip to content

Commit 5bc7e65

Browse files
committed
ENH: Allow overriding sed command via TODOTXT_SED_COMMAND
On most Linux distributions (e.g. Ubuntu), there's no gsed command; the default "sed" is GNU sed with in-place editing capabilities. For those systems, we don't want the redirect + file move workaround applied. However, detecting the sed capabilities is error-prone and just as inefficient as the separate "mv" it would avoid. Instead, add a configuration that users can uncomment. Ideally, package maintainers for Linux distributions that have GNU sed ship with this already commented out in the default configuration.
1 parent 882a50b commit 5bc7e65

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

todo.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ export REPORT_FILE="$TODO_DIR/report.txt"
101101
# Set a default action for calling todo.sh without arguments.
102102
# Also allows for parameters for the action.
103103
# export TODOTXT_DEFAULT_ACTION=''
104+
105+
## sed capabilities
106+
# If you have GNU sed or another sed that supports in-place editing
107+
# via -i[SUFFIX], uncomment this for a minuscule performance gain.
108+
# export TODOTXT_SED_COMMAND=sed

todo.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ oneline_usage="$TODO_SH [-fhpantvV] [-d todo_config] action [task_number] [task_
2929
# Assumption: The in-place argument is the first
3030
# Assumption: Only a single file is processed with sed
3131
sed() {
32-
if command -v gsed &>/dev/null; then
32+
if [ -n "$TODOTXT_SED_COMMAND" ]; then
33+
command "$TODOTXT_SED_COMMAND" "$@"
34+
elif command -v gsed &>/dev/null; then
3335
gsed "$@"
3436
elif [ "$1" = '-i.bak' ]; then
3537
shift

0 commit comments

Comments
 (0)