Compare commits
25 Commits
archive/li
...
archive/de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25e6d7ae24 | ||
|
|
880d829e8e | ||
|
|
7e525ee743 | ||
|
|
d46adadb1d | ||
|
|
d0205b48a6 | ||
|
|
7a4d11812d | ||
|
|
ba66f66e86 | ||
|
|
88ac3d87e6 | ||
|
|
1a2af45b4d | ||
|
|
6424c4c1a0 | ||
|
|
fe5cdcb13a | ||
|
|
bf2ca0ed6a | ||
|
|
62d78a0034 | ||
|
|
e33603939b | ||
|
|
c99543506a | ||
|
|
b4aaba8387 | ||
|
|
493e975199 | ||
|
|
fda31ea260 | ||
|
|
8744167827 | ||
|
|
73e28b7225 | ||
|
|
43bd1b645b | ||
|
|
4db4494f03 | ||
|
|
799840b664 | ||
|
|
54f15a7854 | ||
|
|
17658c852d |
@@ -21,6 +21,7 @@ h2. Quick Links
|
||||
* Original anemic release by "Gina Trapani":http://ginatrapani.org on 5/11/2006.
|
||||
* Raised to great heights by "brainy and dedicated volunteers":http://github.com/ginatrapani/todo.txt-cli/network.
|
||||
* Licensed under the "GPL":http://www.gnu.org/copyleft/gpl.html
|
||||
* "Add-on Directory":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-add-on-directory
|
||||
* "Add-on Directory":https://github.com/ginatrapani/todo.txt-cli/wiki/Todo.sh-Add-on-Directory
|
||||
https://github.com/ginatrapani/todo.txt-cli/wiki/Creating-and-Installing-Add-ons
|
||||
* "Changelog":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-changelog
|
||||
* "Known Bugs":http://github.com/ginatrapani/todo.txt-cli/issues
|
||||
* "Known Bugs":http://github.com/ginatrapani/todo.txt-cli/issues
|
||||
|
||||
@@ -53,6 +53,18 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <<EOF
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the custom hiding
|
||||
#
|
||||
test_todo_session 'checking HIDE_CUSTOM_SUBSTITUTION' <<EOF
|
||||
>>> HIDE_CUSTOM_SUBSTITUTION='[tT]h' todo.sh ls
|
||||
2 aaa zzz is line should be first.
|
||||
3 bbb yyy is line should be second.
|
||||
1 ccc xxx is line should be ird.
|
||||
--
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the filtering of TERM
|
||||
#
|
||||
|
||||
35
tests/t1900-archive.sh
Executable file
35
tests/t1900-archive.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='archive functionality
|
||||
|
||||
Ensure we can archive items successfully.
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
one
|
||||
two
|
||||
three
|
||||
one
|
||||
x done
|
||||
four
|
||||
EOF
|
||||
|
||||
test_todo_session 'archive with duplicates' <<EOF
|
||||
>>> todo.sh archive
|
||||
x done
|
||||
TODO: $HOME/todo.txt archived.
|
||||
EOF
|
||||
|
||||
test_todo_session 'list after archive' <<EOF
|
||||
>>> todo.sh ls
|
||||
5 four
|
||||
1 one
|
||||
4 one
|
||||
3 three
|
||||
2 two
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
103
tests/t1910-deduplicate.sh
Executable file
103
tests/t1910-deduplicate.sh
Executable file
@@ -0,0 +1,103 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='deduplicate functionality
|
||||
|
||||
Ensure we can deduplicate items successfully.
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
duplicated
|
||||
two
|
||||
x done
|
||||
duplicated
|
||||
double task
|
||||
double task
|
||||
three
|
||||
EOF
|
||||
|
||||
test_todo_session 'deduplicate and preserve line numbers' <<EOF
|
||||
>>> todo.sh deduplicate
|
||||
TODO: 2 duplicate task(s) removed
|
||||
|
||||
>>> todo.sh -p ls
|
||||
5 double task
|
||||
1 duplicated
|
||||
7 three
|
||||
2 two
|
||||
3 x done
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'deduplicate without duplicates' <<EOF
|
||||
>>> todo.sh deduplicate
|
||||
TODO: No duplicate tasks found
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
duplicated
|
||||
two
|
||||
x done
|
||||
duplicated
|
||||
double task
|
||||
double task
|
||||
three
|
||||
EOF
|
||||
test_todo_session 'deduplicate and delete lines' <<EOF
|
||||
>>> todo.sh -n deduplicate
|
||||
TODO: 2 duplicate task(s) removed
|
||||
|
||||
>>> todo.sh -p ls
|
||||
4 double task
|
||||
1 duplicated
|
||||
5 three
|
||||
2 two
|
||||
3 x done
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
one
|
||||
duplicated
|
||||
three
|
||||
duplicated
|
||||
duplicated
|
||||
six
|
||||
duplicated
|
||||
EOF
|
||||
test_todo_session 'deduplicate more than two occurrences' <<EOF
|
||||
>>> todo.sh deduplicate
|
||||
TODO: 3 duplicate task(s) removed
|
||||
|
||||
>>> todo.sh -p ls
|
||||
2 duplicated
|
||||
1 one
|
||||
6 six
|
||||
3 three
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
normal task
|
||||
a [1mbold[0m task
|
||||
something else
|
||||
a [1mbold[0m task
|
||||
something more
|
||||
EOF
|
||||
test_todo_session 'deduplicate with non-printable duplicates' <<EOF
|
||||
>>> todo.sh deduplicate
|
||||
TODO: 1 duplicate task(s) removed
|
||||
|
||||
>>> todo.sh -p ls
|
||||
2 a [1mbold[0m task
|
||||
1 normal task
|
||||
3 something else
|
||||
5 something more
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
96
tests/t1950-report.sh
Executable file
96
tests/t1950-report.sh
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='report functionality
|
||||
|
||||
This test checks the reporting and the format of the report file.
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +flowers @outside
|
||||
stop and think
|
||||
smell the coffee +wakeup
|
||||
make the coffee +wakeup
|
||||
visit http://example.com
|
||||
EOF
|
||||
|
||||
test_todo_session 'create new report' <<EOF
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
2009-02-13T04:40:00 5 0
|
||||
TODO: Report file updated.
|
||||
|
||||
>>> todo.sh -p list
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
4 make the coffee +wakeup
|
||||
3 smell the coffee +wakeup
|
||||
2 stop and think
|
||||
5 visit http://example.com
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'report of done tasks' <<EOF
|
||||
>>> todo.sh -A do 3
|
||||
3 x 2009-02-13 smell the coffee +wakeup
|
||||
TODO: 3 marked as done.
|
||||
x 2009-02-13 smell the coffee +wakeup
|
||||
TODO: $HOME/todo.txt archived.
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
2009-02-13T04:40:00 4 1
|
||||
TODO: Report file updated.
|
||||
|
||||
>>> todo.sh -p list
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
3 make the coffee +wakeup
|
||||
2 stop and think
|
||||
4 visit http://example.com
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'report performs archiving' <<EOF
|
||||
>>> todo.sh -a do 3
|
||||
3 x 2009-02-13 make the coffee +wakeup
|
||||
TODO: 3 marked as done.
|
||||
|
||||
>>> todo.sh report
|
||||
x 2009-02-13 make the coffee +wakeup
|
||||
TODO: $HOME/todo.txt archived.
|
||||
2009-02-13T04:40:00 3 2
|
||||
TODO: Report file updated.
|
||||
|
||||
>>> todo.sh -p list
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
2 stop and think
|
||||
3 visit http://example.com
|
||||
--
|
||||
TODO: 3 of 3 tasks shown
|
||||
|
||||
>>> todo.sh -p listfile done.txt
|
||||
2 x 2009-02-13 make the coffee +wakeup
|
||||
1 x 2009-02-13 smell the coffee +wakeup
|
||||
--
|
||||
DONE: 2 of 2 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'report is unchanged when no changes' <<EOF
|
||||
>>> cat report.txt
|
||||
2009-02-13T04:40:00 5 0
|
||||
2009-02-13T04:40:00 4 1
|
||||
2009-02-13T04:40:00 3 2
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
2009-02-13T04:40:00 3 2
|
||||
TODO: Report file is up-to-date.
|
||||
|
||||
>>> cat report.txt
|
||||
2009-02-13T04:40:00 5 0
|
||||
2009-02-13T04:40:00 4 1
|
||||
2009-02-13T04:40:00 3 2
|
||||
EOF
|
||||
|
||||
test_done
|
||||
@@ -85,13 +85,9 @@ TODO: $HOME/todo.txt archived.
|
||||
TODO: 5 of 5 tasks shown
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
2009-02-13T04:40:00 5 1
|
||||
TODO: Report file updated.
|
||||
2009-02-13-04:40:00 5 1
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: Report file updated.
|
||||
2009-02-13-04:40:00 5 1
|
||||
2009-02-13-04:40:00 5 1
|
||||
|
||||
>>> todo.sh append g a
|
||||
usage: todo.sh append ITEM# "TEXT TO APPEND"
|
||||
|
||||
156
todo.sh
156
todo.sh
@@ -50,6 +50,7 @@ shorthelp()
|
||||
append|app ITEM# "TEXT TO APPEND"
|
||||
archive
|
||||
command [ACTIONS]
|
||||
deduplicate
|
||||
del|rm ITEM# [TERM]
|
||||
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
||||
do ITEM#[, ITEM#, ITEM#, ...]
|
||||
@@ -67,6 +68,8 @@ shorthelp()
|
||||
report
|
||||
shorthelp
|
||||
|
||||
Actions can be added and overridden using scripts in the actions
|
||||
directory.
|
||||
EndHelp
|
||||
|
||||
# Only list the one-line usage from the add-on actions. This assumes that
|
||||
@@ -87,10 +90,10 @@ help()
|
||||
|
||||
Options:
|
||||
-@
|
||||
Hide context names in list output. Use twice to show context
|
||||
Hide context names in list output. Use twice to show context
|
||||
names (default).
|
||||
-+
|
||||
Hide project names in list output. Use twice to show project
|
||||
Hide project names in list output. Use twice to show project
|
||||
names (default).
|
||||
-c
|
||||
Color mode
|
||||
@@ -103,7 +106,7 @@ help()
|
||||
-p
|
||||
Plain mode turns off colors
|
||||
-P
|
||||
Hide priority labels in list output. Use twice to show
|
||||
Hide priority labels in list output. Use twice to show
|
||||
priority labels (default).
|
||||
-a
|
||||
Don't auto-archive tasks automatically on completion
|
||||
@@ -162,7 +165,6 @@ help()
|
||||
Adds FIRST THING I NEED TO DO to your todo.txt on its own line and
|
||||
Adds SECOND THING I NEED TO DO to you todo.txt on its own line.
|
||||
Project and context notation optional.
|
||||
Quotes optional.
|
||||
|
||||
addto DEST "TEXT TO ADD"
|
||||
Adds a line of text to any file located in the todo.txt directory.
|
||||
@@ -180,6 +182,9 @@ help()
|
||||
Runs the remaining arguments using only todo.sh builtins.
|
||||
Will not call any .todo.actions.d scripts.
|
||||
|
||||
deduplicate
|
||||
Removes duplicate lines from todo.txt.
|
||||
|
||||
del ITEM# [TERM]
|
||||
rm ITEM# [TERM]
|
||||
Deletes the task on line ITEM# in todo.txt.
|
||||
@@ -199,13 +204,19 @@ help()
|
||||
list [TERM...]
|
||||
ls [TERM...]
|
||||
Displays all tasks that contain TERM(s) sorted by priority with line
|
||||
numbers. If no TERM specified, lists entire todo.txt.
|
||||
numbers. Each task must match all TERM(s) (logical AND); to display
|
||||
tasks that contain any TERM (logical OR), use
|
||||
"TERM1\|TERM2\|..." (with quotes), or TERM1\\\|TERM2 (unquoted).
|
||||
Hides all tasks that contain TERM(s) preceded by a
|
||||
minus sign (i.e. -TERM). If no TERM specified, lists entire todo.txt.
|
||||
|
||||
listall [TERM...]
|
||||
lsa [TERM...]
|
||||
Displays all the lines in todo.txt AND done.txt that contain TERM(s)
|
||||
sorted by priority with line numbers. If no TERM specified, lists
|
||||
entire todo.txt AND done.txt concatenated and sorted.
|
||||
sorted by priority with line numbers. Hides all tasks that
|
||||
contain TERM(s) preceded by a minus sign (i.e. -TERM). If no
|
||||
TERM specified, lists entire todo.txt AND done.txt
|
||||
concatenated and sorted.
|
||||
|
||||
listcon
|
||||
lsc
|
||||
@@ -215,19 +226,23 @@ help()
|
||||
lf [SRC [TERM...]]
|
||||
Displays all the lines in SRC file located in the todo.txt directory,
|
||||
sorted by priority with line numbers. If TERM specified, lists
|
||||
all lines that contain TERM in SRC file.
|
||||
all lines that contain TERM(s) in SRC file. Hides all tasks that
|
||||
contain TERM(s) preceded by a minus sign (i.e. -TERM).
|
||||
Without any arguments, the names of all text files in the todo.txt
|
||||
directory are listed.
|
||||
|
||||
|
||||
listpri [PRIORITY] [TERM...]
|
||||
lsp [PRIORITY] [TERM...]
|
||||
Displays all tasks prioritized PRIORITY.
|
||||
If no PRIORITY specified, lists all prioritized tasks.
|
||||
If TERM specified, lists only prioritized tasks that contain TERM.
|
||||
If TERM specified, lists only prioritized tasks that contain TERM(s).
|
||||
Hides all tasks that contain TERM(s) preceded by a minus sign
|
||||
(i.e. -TERM).
|
||||
|
||||
listproj
|
||||
lsprj
|
||||
Lists all the projects that start with the + sign in todo.txt.
|
||||
Lists all the projects (terms that start with a + sign) in
|
||||
todo.txt.
|
||||
|
||||
move ITEM# DEST [SRC]
|
||||
mv ITEM# DEST [SRC]
|
||||
@@ -245,7 +260,7 @@ help()
|
||||
p ITEM# PRIORITY
|
||||
Adds PRIORITY to task on line ITEM#. If the task is already
|
||||
prioritized, replaces current priority with new PRIORITY.
|
||||
PRIORITY must be an uppercase letter between A and Z.
|
||||
PRIORITY must be a letter between A and Z.
|
||||
|
||||
replace ITEM# "UPDATED TODO"
|
||||
Replaces task on line ITEM# with UPDATED TODO.
|
||||
@@ -256,7 +271,6 @@ help()
|
||||
shorthelp
|
||||
List the one-line usage of all built-in and add-on actions.
|
||||
|
||||
|
||||
EndActionsHelp
|
||||
|
||||
addonHelp
|
||||
@@ -353,20 +367,6 @@ getNewtodo()
|
||||
[ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item."
|
||||
}
|
||||
|
||||
archive()
|
||||
{
|
||||
#defragment blank lines
|
||||
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
cp "$TODO_FILE" "$TMP_FILE"
|
||||
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "TODO: $TODO_FILE archived."
|
||||
fi
|
||||
}
|
||||
|
||||
replaceOrPrepend()
|
||||
{
|
||||
action=$1; shift
|
||||
@@ -775,7 +775,11 @@ _list() {
|
||||
fi
|
||||
items=$(
|
||||
sed = "$src" \
|
||||
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||
| sed '''
|
||||
N
|
||||
s/^/ /
|
||||
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
|
||||
''' \
|
||||
| grep -v "^[ 0-9]\+ *$"
|
||||
)
|
||||
if [ "${filter_command}" ]; then
|
||||
@@ -812,8 +816,9 @@ _list() {
|
||||
}
|
||||
''' \
|
||||
| sed '''
|
||||
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||
s/'"${HIDE_PROJECTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CONTEXTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CUSTOM_SUBSTITUTION:-^}"'//g
|
||||
''' \
|
||||
| eval ${TODOTXT_FINAL_FILTER} \
|
||||
)
|
||||
@@ -933,7 +938,15 @@ case $action in
|
||||
;;
|
||||
|
||||
"archive" )
|
||||
archive;;
|
||||
# defragment blank lines
|
||||
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "TODO: $TODO_FILE archived."
|
||||
fi
|
||||
;;
|
||||
|
||||
"del" | "rm" )
|
||||
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||
@@ -991,7 +1004,7 @@ case $action in
|
||||
|
||||
# Split multiple depri's, if comma separated change to whitespace separated
|
||||
# Loop the 'depri' function for each item
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
for item in ${*//,/ }; do
|
||||
getTodo "$item"
|
||||
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
@@ -1015,7 +1028,7 @@ case $action in
|
||||
|
||||
# Split multiple do's, if comma separated change to whitespace separated
|
||||
# Loop the 'do' function for each item
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
for item in ${*//,/ }; do
|
||||
getTodo "$item"
|
||||
|
||||
# Check if this item has already been done
|
||||
@@ -1035,7 +1048,9 @@ case $action in
|
||||
done
|
||||
|
||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||
archive
|
||||
# Recursively invoke the script to allow overriding of the archive
|
||||
# action.
|
||||
"$TODO_FULL_SH" archive
|
||||
fi
|
||||
;;
|
||||
|
||||
@@ -1200,22 +1215,69 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
;;
|
||||
|
||||
"report" )
|
||||
#archive first
|
||||
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
# archive first
|
||||
# Recursively invoke the script to allow overriding of the archive
|
||||
# action.
|
||||
"$TODO_FULL_SH" archive
|
||||
|
||||
NUMLINES=$( sed -n '$ =' "$TODO_FILE" )
|
||||
if [ ${NUMLINES:-0} = "0" ]; then
|
||||
echo "datetime todos dones" >> "$REPORT_FILE"
|
||||
fi
|
||||
#now report
|
||||
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
|
||||
echo ${TDONE:-0})
|
||||
echo $TECHO >> "$REPORT_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||
cat "$REPORT_FILE"
|
||||
NEWDATA="${TOTAL:-0} ${TDONE:-0}"
|
||||
LASTREPORT=$(sed -ne '$p' "$REPORT_FILE")
|
||||
LASTDATA=${LASTREPORT#* } # Strip timestamp.
|
||||
if [ "$LASTDATA" = "$NEWDATA" ]; then
|
||||
echo "$LASTREPORT"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file is up-to-date."
|
||||
else
|
||||
NEWREPORT="$(date +%Y-%m-%dT%T) ${NEWDATA}"
|
||||
echo "${NEWREPORT}" >> "$REPORT_FILE"
|
||||
echo "${NEWREPORT}"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||
fi
|
||||
;;
|
||||
|
||||
"deduplicate" )
|
||||
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||
deduplicateSedCommand='d'
|
||||
else
|
||||
deduplicateSedCommand='s/^.*//; p'
|
||||
fi
|
||||
|
||||
# To determine the difference when deduplicated lines are preserved, only
|
||||
# non-empty lines must be counted.
|
||||
originalTaskNum=$( sed -e '/./!d' "$TODO_FILE" | sed -n '$ =' )
|
||||
|
||||
# Look for duplicate lines and discard the second occurrence.
|
||||
# We start with an empty hold space on the first line. For each line:
|
||||
# G - appends newline + hold space to the pattern space
|
||||
# s/\n/&&/; - double up the first new line so we catch adjacent dups
|
||||
# /^\([^\n]*\n\).*\n\1/b dedup
|
||||
# If the first line of the hold space shows up again later as an
|
||||
# entire line, it's a duplicate. Jump to the "dedup" label, where
|
||||
# either of the following is executed, depending on whether empty
|
||||
# lines should be preserved:
|
||||
# d - Delete the current pattern space, quit this line and
|
||||
# move on to the next, or:
|
||||
# s/^.*//; p - Clear the task text, print this line and move on to
|
||||
# the next.
|
||||
# s/\n//; - else (no duplicate), drop the doubled newline
|
||||
# h; - replace the hold space with the expanded pattern space
|
||||
# P; - print up to the first newline (that is, the input line)
|
||||
# b - end processing of the current line
|
||||
sed -i.bak -n \
|
||||
-e 'G; s/\n/&&/; /^\([^\n]*\n\).*\n\1/b dedup' \
|
||||
-e 's/\n//; h; P; b' \
|
||||
-e ':dedup' \
|
||||
-e "$deduplicateSedCommand" \
|
||||
"$TODO_FILE"
|
||||
|
||||
newTaskNum=$( sed -e '/./!d' "$TODO_FILE" | sed -n '$ =' )
|
||||
deduplicateNum=$(( originalTaskNum - newTaskNum ))
|
||||
if [ $deduplicateNum -eq 0 ]; then
|
||||
echo "TODO: No duplicate tasks found"
|
||||
else
|
||||
echo "TODO: $deduplicateNum duplicate task(s) removed"
|
||||
fi
|
||||
;;
|
||||
|
||||
* )
|
||||
|
||||
@@ -38,20 +38,28 @@ _todo()
|
||||
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
|
||||
@*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);;
|
||||
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then
|
||||
local item=$(TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | head -n 1)
|
||||
|
||||
# Remove the (padded) task number; we prepend the
|
||||
# user-provided $cur.
|
||||
item=${item#* }
|
||||
|
||||
# Remove the timestamp prepended by the -t option;
|
||||
# there's no todo.txt option for that yet.
|
||||
item=${item#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] }
|
||||
|
||||
# user-provided $cur instead.
|
||||
# Remove the timestamp prepended by the -t option,
|
||||
# and the done date (for done tasks); there's no
|
||||
# todo.txt option for that yet.
|
||||
# But keep priority and "x"; they're short and may
|
||||
# provide useful context.
|
||||
# Remove any trailing whitespace; the Bash
|
||||
# completion inserts a trailing space itself.
|
||||
# Finally, limit the output to a single line just as
|
||||
# a safety check of the ls action output.
|
||||
local todo=$( \
|
||||
TODOTXT_VERBOSE=0 todo.sh -@ -+ -p -x command ls "^ *${cur} " | \
|
||||
sed -e 's/^ *[0-9]\+ //' -e 's/\((.) \)[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \
|
||||
-e 's/\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
|
||||
-e 's/[[:space:]]*$//' \
|
||||
-e '1q' \
|
||||
)
|
||||
# Append task text as a shell comment. This
|
||||
# completion can be a safety check before a
|
||||
# destructive todo.txt operation.
|
||||
[ "$item" ] && COMPREPLY[0]="$cur # $item"
|
||||
[ "$todo" ] && COMPREPLY[0]="$cur # $todo"
|
||||
return 0
|
||||
else
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user