Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no end-of-line bug #295

Merged
merged 9 commits into from
Mar 29, 2020
13 changes: 13 additions & 0 deletions tests/t1000-addlist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,17 @@ TODO: 1 added.
TODO: 1 of 1 tasks shown
EOF

echo -n 'this is a first task without newline' > todo.txt
test_todo_session 'add to file without EOL' <<EOF
>>> todo.sh add "a second task"
2 a second task
TODO: 2 added.

>>> todo.sh list
2 a second task
1 this is a first task without newline
--
TODO: 2 of 2 tasks shown
EOF

test_done
Expand Down
74 changes: 74 additions & 0 deletions tests/t1850-move.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
#

test_description='basic move functionality
'
. ./test-lib.sh

cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
EOF
cat > done.txt <<EOF
x 2009-02-13 make the coffee +wakeup
x 2009-02-13 smell the coffee +wakeup
EOF
test_todo_session 'basic move with implicit source' <<EOF
>>> todo.sh -f move 1 done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g"
1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 moved from 'todo.txt' to 'done.txt'.

>>> todo.sh -p ls
2 (A) notice the sunflowers
--
TODO: 1 of 1 tasks shown

>>> todo.sh -p listfile done.txt
3 (B) smell the uppercase Roses +flowers @outside
1 x 2009-02-13 make the coffee +wakeup
2 x 2009-02-13 smell the coffee +wakeup
--
DONE: 3 of 3 tasks shown
EOF

test_todo_session 'basic move with passed source' <<EOF
>>> todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g"
2 x 2009-02-13 smell the coffee +wakeup
TODO: 2 moved from 'done.txt' to 'todo.txt'.

>>> todo.sh -p ls
2 (A) notice the sunflowers
3 x 2009-02-13 smell the coffee +wakeup
--
TODO: 2 of 2 tasks shown

>>> todo.sh -p listfile done.txt
3 (B) smell the uppercase Roses +flowers @outside
1 x 2009-02-13 make the coffee +wakeup
--
DONE: 2 of 2 tasks shown
EOF

echo -n 'this is a first task without newline' > todo.txt
cat > done.txt <<EOF
x 2009-02-13 make the coffee +wakeup
x 2009-02-13 smell the coffee +wakeup
EOF
test_todo_session 'move to destination without EOL' <<EOF
>>> todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g"
2 x 2009-02-13 smell the coffee +wakeup
TODO: 2 moved from 'done.txt' to 'todo.txt'.

>>> todo.sh -p ls
1 this is a first task without newline
2 x 2009-02-13 smell the coffee +wakeup
--
TODO: 2 of 2 tasks shown

>>> todo.sh -p listfile done.txt
1 x 2009-02-13 make the coffee +wakeup
--
DONE: 1 of 1 tasks shown
EOF

test_done
8 changes: 8 additions & 0 deletions todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down