Fix/noeol (#295)

* Handle missing EOL in todo.txt

This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876).

Fixes #294

* Tests: Add basic coverage of move

* Handle missing EOL in todo.txt for move, too

This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.

* Refactoring: Extract fixMissingEndOfLine()

* FIX: Compatibility: sed \+ multi not supported on MacOS

Use the POSIX \{1,\} instead.

Co-authored-by: Ali Karbassi <ali@karbassi.com>
This commit is contained in:
Ingo Karkat
2020-03-29 19:03:33 +02:00
committed by GitHub
parent 13b451b81d
commit 861ad5ec41
3 changed files with 95 additions and 0 deletions

View File

@@ -466,6 +466,12 @@ replaceOrPrepend()
fi
}
fixMissingEndOfLine()
{
# Parameters: $1: todo file; empty means $TODO_FILE.
sed -i.bak -e '$a\' "${1:-$TODO_FILE}"
}
uppercasePriority()
{
# Precondition: $input contains task text for which to uppercase priority.
@@ -809,6 +815,7 @@ _addto() {
input=$(echo -n "($TODOTXT_PRIORITY_ON_ADD) " ; echo "$input")
fi
fi
fixMissingEndOfLine "$file"
echo "$input" >> "$file"
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
TASKNUM=$(sed -n '$ =' "$file")
@@ -1339,6 +1346,7 @@ case $action in
# leave blank line behind (preserves line numbers)
sed -i.bak -e "${item}s/^.*//" "$src"
fi
fixMissingEndOfLine "$dest"
echo "$todo" >> "$dest"
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then