Compare commits
6 Commits
archive/li
...
archive/ne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7ffb96695 | ||
|
|
67e0d9dd98 | ||
|
|
1160ae1276 | ||
|
|
534184e4dd | ||
|
|
cd2f585fb6 | ||
|
|
492d98e50a |
@@ -21,7 +21,6 @@ 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":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
|
||||
* "Add-on Directory":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-add-on-directory
|
||||
* "Changelog":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-changelog
|
||||
* "Known Bugs":http://github.com/ginatrapani/todo.txt-cli/issues
|
||||
@@ -45,8 +45,6 @@ test_expect_success 'null listpri a' '
|
||||
cat > expect <<EOF
|
||||
--
|
||||
TODO: 0 of 0 tasks shown
|
||||
DONE: 0 of 0 tasks shown
|
||||
total 0 of 0 tasks shown
|
||||
EOF
|
||||
|
||||
test_expect_success 'null lsa' '
|
||||
|
||||
@@ -53,18 +53,6 @@ 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
|
||||
#
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='listall functionality
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
smell the uppercase Roses +flowers @outside
|
||||
x 2011-08-08 tend the garden @outside
|
||||
notice the sunflowers
|
||||
x 2011-12-26 go outside +wakeup
|
||||
(A) stop
|
||||
EOF
|
||||
cat > done.txt <<EOF
|
||||
x 2011-12-01 eat breakfast
|
||||
x 2011-12-05 smell the coffee +wakeup
|
||||
EOF
|
||||
|
||||
test_todo_session 'basic listall' <<EOF
|
||||
>>> todo.sh -p listall
|
||||
5 (A) stop
|
||||
3 notice the sunflowers
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
2 x 2011-08-08 tend the garden @outside
|
||||
0 x 2011-12-01 eat breakfast
|
||||
0 x 2011-12-05 smell the coffee +wakeup
|
||||
4 x 2011-12-26 go outside +wakeup
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
DONE: 2 of 2 tasks shown
|
||||
total 7 of 7 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'listall highlighting' <<EOF
|
||||
>>> todo.sh listall
|
||||
[1;33m5 (A) stop[0m
|
||||
3 notice the sunflowers
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
[0;37m2 x 2011-08-08 tend the garden @outside[0m
|
||||
[0;37m0 x 2011-12-01 eat breakfast[0m
|
||||
[0;37m0 x 2011-12-05 smell the coffee +wakeup[0m
|
||||
[0;37m4 x 2011-12-26 go outside +wakeup[0m
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
DONE: 2 of 2 tasks shown
|
||||
total 7 of 7 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'listall nonverbose' <<EOF
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh -p listall
|
||||
5 (A) stop
|
||||
3 notice the sunflowers
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
2 x 2011-08-08 tend the garden @outside
|
||||
0 x 2011-12-01 eat breakfast
|
||||
0 x 2011-12-05 smell the coffee +wakeup
|
||||
4 x 2011-12-26 go outside +wakeup
|
||||
EOF
|
||||
|
||||
test_todo_session 'listall filtering' <<EOF
|
||||
>>> todo.sh -p listall @outside
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
2 x 2011-08-08 tend the garden @outside
|
||||
--
|
||||
TODO: 2 of 5 tasks shown
|
||||
DONE: 0 of 2 tasks shown
|
||||
total 2 of 7 tasks shown
|
||||
|
||||
>>> todo.sh -p listall the
|
||||
3 notice the sunflowers
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
2 x 2011-08-08 tend the garden @outside
|
||||
0 x 2011-12-05 smell the coffee +wakeup
|
||||
--
|
||||
TODO: 3 of 5 tasks shown
|
||||
DONE: 1 of 2 tasks shown
|
||||
total 4 of 7 tasks shown
|
||||
|
||||
>>> todo.sh -p listall breakfast
|
||||
0 x 2011-12-01 eat breakfast
|
||||
--
|
||||
TODO: 0 of 5 tasks shown
|
||||
DONE: 1 of 2 tasks shown
|
||||
total 1 of 7 tasks shown
|
||||
|
||||
>>> todo.sh -p listall doesnotmatch
|
||||
--
|
||||
TODO: 0 of 5 tasks shown
|
||||
DONE: 0 of 2 tasks shown
|
||||
total 0 of 7 tasks shown
|
||||
EOF
|
||||
|
||||
cat >> done.txt <<EOF
|
||||
x 2010-01-01 old task 1
|
||||
x 2010-01-01 old task 2
|
||||
x 2010-01-01 old task 3
|
||||
x 2010-01-01 old task 4
|
||||
EOF
|
||||
test_todo_session 'listall number width' <<EOF
|
||||
>>> todo.sh -p listall
|
||||
5 (A) stop
|
||||
3 notice the sunflowers
|
||||
1 smell the uppercase Roses +flowers @outside
|
||||
0 x 2010-01-01 old task 1
|
||||
0 x 2010-01-01 old task 2
|
||||
0 x 2010-01-01 old task 3
|
||||
0 x 2010-01-01 old task 4
|
||||
2 x 2011-08-08 tend the garden @outside
|
||||
0 x 2011-12-01 eat breakfast
|
||||
0 x 2011-12-05 smell the coffee +wakeup
|
||||
4 x 2011-12-26 go outside +wakeup
|
||||
--
|
||||
TODO: 5 of 5 tasks shown
|
||||
DONE: 6 of 6 tasks shown
|
||||
total 11 of 11 tasks shown
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh add new task 1
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh add new task 2
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh add new task 3
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh add new task 4
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh add new task 5
|
||||
|
||||
>>> todo.sh -p listall
|
||||
05 (A) stop
|
||||
06 new task 1
|
||||
07 new task 2
|
||||
08 new task 3
|
||||
09 new task 4
|
||||
10 new task 5
|
||||
03 notice the sunflowers
|
||||
01 smell the uppercase Roses +flowers @outside
|
||||
00 x 2010-01-01 old task 1
|
||||
00 x 2010-01-01 old task 2
|
||||
00 x 2010-01-01 old task 3
|
||||
00 x 2010-01-01 old task 4
|
||||
02 x 2011-08-08 tend the garden @outside
|
||||
00 x 2011-12-01 eat breakfast
|
||||
00 x 2011-12-05 smell the coffee +wakeup
|
||||
04 x 2011-12-26 go outside +wakeup
|
||||
--
|
||||
TODO: 10 of 10 tasks shown
|
||||
DONE: 6 of 6 tasks shown
|
||||
total 16 of 16 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
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 action
|
||||
something else
|
||||
a [1mbold[0m action
|
||||
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 action
|
||||
1 normal task
|
||||
3 something else
|
||||
5 something more
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
@@ -85,10 +85,12 @@ TODO: $HOME/todo.txt archived.
|
||||
TODO: 5 of 5 tasks shown
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
TODO: Report file updated.
|
||||
2009-02-13-04:40:00 5 1
|
||||
|
||||
>>> todo.sh report
|
||||
TODO: $HOME/todo.txt archived.
|
||||
TODO: Report file updated.
|
||||
2009-02-13-04:40:00 5 1
|
||||
2009-02-13-04:40:00 5 1
|
||||
|
||||
133
todo.sh
133
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,8 +68,6 @@ 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
|
||||
@@ -164,6 +163,7 @@ 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.
|
||||
@@ -181,6 +181,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.
|
||||
@@ -200,19 +203,13 @@ help()
|
||||
list [TERM...]
|
||||
ls [TERM...]
|
||||
Displays all tasks that contain TERM(s) sorted by priority with line
|
||||
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.
|
||||
numbers. 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. 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.
|
||||
sorted by priority with line numbers. If no TERM specified, lists
|
||||
entire todo.txt AND done.txt concatenated and sorted.
|
||||
|
||||
listcon
|
||||
lsc
|
||||
@@ -222,8 +219,7 @@ 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(s) in SRC file. Hides all tasks that
|
||||
contain TERM(s) preceded by a minus sign (i.e. -TERM).
|
||||
all lines that contain TERM in SRC file.
|
||||
Without any arguments, the names of all text files in the todo.txt
|
||||
directory are listed.
|
||||
|
||||
@@ -231,14 +227,11 @@ help()
|
||||
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(s).
|
||||
Hides all tasks that contain TERM(s) preceded by a minus sign
|
||||
(i.e. -TERM).
|
||||
If TERM specified, lists only prioritized tasks that contain TERM.
|
||||
|
||||
listproj
|
||||
lsprj
|
||||
Lists all the projects (terms that start with a + sign) in
|
||||
todo.txt.
|
||||
Lists all the projects that start with the + sign in todo.txt.
|
||||
|
||||
move ITEM# DEST [SRC]
|
||||
mv ITEM# DEST [SRC]
|
||||
@@ -256,7 +249,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 a letter between A and Z.
|
||||
PRIORITY must be an uppercase letter between A and Z.
|
||||
|
||||
replace ITEM# "UPDATED TODO"
|
||||
Replaces task on line ITEM# with UPDATED TODO.
|
||||
@@ -267,6 +260,7 @@ help()
|
||||
shorthelp
|
||||
List the one-line usage of all built-in and add-on actions.
|
||||
|
||||
|
||||
EndActionsHelp
|
||||
|
||||
addonHelp
|
||||
@@ -363,20 +357,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
|
||||
@@ -785,12 +765,8 @@ _list() {
|
||||
fi
|
||||
items=$(
|
||||
sed = "$src" \
|
||||
| sed -e '''
|
||||
N
|
||||
s/^/ /
|
||||
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
|
||||
/^[ 0-9]\{1,\} *$/d
|
||||
'''
|
||||
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||
| grep -v "^[ 0-9]\+ *$"
|
||||
)
|
||||
if [ "${filter_command}" ]; then
|
||||
filtered_items=$(echo -n "$items" | eval "${filter_command}")
|
||||
@@ -826,9 +802,8 @@ _list() {
|
||||
}
|
||||
''' \
|
||||
| sed '''
|
||||
s/'"${HIDE_PROJECTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CONTEXTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CUSTOM_SUBSTITUTION:-^}"'//g
|
||||
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||
''' \
|
||||
| eval ${TODOTXT_FINAL_FILTER} \
|
||||
)
|
||||
@@ -948,7 +923,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
|
||||
@@ -1006,7 +989,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 ${*//,/ }; do
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
getTodo "$item"
|
||||
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
@@ -1030,7 +1013,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 ${*//,/ }; do
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
getTodo "$item"
|
||||
|
||||
# Check if this item has already been done
|
||||
@@ -1050,7 +1033,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
|
||||
;;
|
||||
|
||||
@@ -1083,20 +1068,7 @@ case $action in
|
||||
shift ## Was lsa; new $1 is first search term
|
||||
|
||||
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||
|
||||
post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=${#TOTAL} '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
|
||||
TODOTXT_VERBOSE=0 _list "$TMP_FILE" "$@"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$TODO_FILE" "$@" | sed -n '$ =')
|
||||
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$DONE_FILE" "$@" | sed -n '$ =')
|
||||
echo "--"
|
||||
echo "$(getPrefix "$TODO_FILE"): ${TASKNUM:-0} of ${TOTAL:-0} tasks shown"
|
||||
echo "$(getPrefix "$DONE_FILE"): ${DONENUM:-0} of ${TDONE:-0} tasks shown"
|
||||
echo "total $((TASKNUM + DONENUM)) of $((TOTAL + TDONE)) tasks shown"
|
||||
fi
|
||||
_list "$TMP_FILE" "$@"
|
||||
;;
|
||||
|
||||
"listfile" | "lf" )
|
||||
@@ -1216,8 +1188,9 @@ 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"
|
||||
# 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
|
||||
@@ -1233,6 +1206,42 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
cat "$REPORT_FILE"
|
||||
;;
|
||||
|
||||
"deduplicate" )
|
||||
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||
deduplicateSedCommand='d'
|
||||
else
|
||||
deduplicateSedCommand='{ s/^.*//; p; b }'
|
||||
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/
|
||||
# If the first line of the hold space shows up again later as an
|
||||
# entire line, it's a duplicate.
|
||||
# d; - Delete the current pattern space, quit this line
|
||||
# and move on to the next, or:
|
||||
# { s/^.*//; p; b }; - Clear the task text, print this line and move on
|
||||
# to the next.
|
||||
# s/\n//; - else, 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)
|
||||
sed -i.bak -n 'G; s/\n/&&/; /^\([^\n]*\n\).*\n\1/'"$deduplicateSedCommand"'; s/\n//; h; P' "$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
|
||||
;;
|
||||
|
||||
* )
|
||||
usage;;
|
||||
esac
|
||||
|
||||
@@ -38,28 +38,20 @@ _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 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' \
|
||||
)
|
||||
# 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] }
|
||||
|
||||
# Append task text as a shell comment. This
|
||||
# completion can be a safety check before a
|
||||
# destructive todo.txt operation.
|
||||
[ "$todo" ] && COMPREPLY[0]="$cur # $todo"
|
||||
[ "$item" ] && COMPREPLY[0]="$cur # $item"
|
||||
return 0
|
||||
else
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user