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:
8
todo.sh
8
todo.sh
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user