Compare commits
1 Commits
archive/re
...
archive/li
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
272cd5e469 |
@@ -21,7 +21,6 @@ h2. Quick Links
|
|||||||
* Original anemic release by "Gina Trapani":http://ginatrapani.org on 5/11/2006.
|
* 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.
|
* 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
|
* 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
|
* "Add-on Directory":http://wiki.github.com/ginatrapani/todo.txt-cli/todosh-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
|
* "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
|
||||||
@@ -1,57 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
[ "x$TERM" != "xdumb" ] && (
|
|
||||||
export TERM &&
|
|
||||||
[ -t 1 ] &&
|
|
||||||
tput bold >/dev/null 2>&1 &&
|
|
||||||
tput setaf 1 >/dev/null 2>&1 &&
|
|
||||||
tput sgr0 >/dev/null 2>&1
|
|
||||||
) &&
|
|
||||||
color=t
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
--no-color)
|
|
||||||
color=; shift ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if test -n "$color"; then
|
|
||||||
say_color () {
|
|
||||||
(
|
|
||||||
export TERM
|
|
||||||
case "$1" in
|
|
||||||
error) tput bold; tput setaf 1;; # bold red
|
|
||||||
skip) tput bold; tput setaf 2;; # bold green
|
|
||||||
pass) tput setaf 2;; # green
|
|
||||||
info) tput setaf 3;; # brown
|
|
||||||
*) test -n "$quiet" && return;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
printf "* %s" "$*"
|
|
||||||
tput sgr0
|
|
||||||
echo
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
say_color() {
|
|
||||||
test -z "$1" && test -n "$quiet" && return
|
|
||||||
shift
|
|
||||||
echo "* $*"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
get_color()
|
|
||||||
{
|
|
||||||
# Only use the supplied color if there are actually instances of that
|
|
||||||
# type, so that a clean test run does not distract the user by the
|
|
||||||
# appearance of the error highlighting.
|
|
||||||
if [ ${1:?} -eq 0 ]
|
|
||||||
then
|
|
||||||
echo 'info'
|
|
||||||
else
|
|
||||||
echo "${2:-info}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fixed=0
|
fixed=0
|
||||||
success=0
|
success=0
|
||||||
@@ -80,8 +27,8 @@ do
|
|||||||
done <"$file"
|
done <"$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
say_color 'info' "$(printf "%-8s%d\n" fixed $fixed)"
|
printf "%-8s%d\n" fixed $fixed
|
||||||
say_color "$(get_color "$success" 'pass')" "$(printf "%-8s%d\n" success $success)"
|
printf "%-8s%d\n" success $success
|
||||||
say_color "$(get_color "$failed" 'error')" "$(printf "%-8s%d\n" failed $failed)"
|
printf "%-8s%d\n" failed $failed
|
||||||
say_color "$(get_color "$broken" 'error')" "$(printf "%-8s%d\n" broken $broken)"
|
printf "%-8s%d\n" broken $broken
|
||||||
say_color 'info' "$(printf "%-8s%d\n" total $total)"
|
printf "%-8s%d\n" total $total
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ test_expect_success 'null listpri a' '
|
|||||||
cat > expect <<EOF
|
cat > expect <<EOF
|
||||||
--
|
--
|
||||||
TODO: 0 of 0 tasks shown
|
TODO: 0 of 0 tasks shown
|
||||||
DONE: 0 of 0 tasks shown
|
|
||||||
total 0 of 0 tasks shown
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'null lsa' '
|
test_expect_success 'null lsa' '
|
||||||
|
|||||||
@@ -61,42 +61,6 @@ TODO: 0 of 5 tasks shown
|
|||||||
TODO: 0 of 5 tasks shown
|
TODO: 0 of 5 tasks shown
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > todo.txt <<EOF
|
|
||||||
(B) smell the uppercase Roses +flowers @outside
|
|
||||||
(X) clean the house from A-Z
|
|
||||||
(C) notice the sunflowers
|
|
||||||
(X) listen to music
|
|
||||||
buy more records from artists A-Z
|
|
||||||
EOF
|
|
||||||
test_todo_session 'listpri filtering priority ranges' <<EOF
|
|
||||||
>>> todo.sh -p listpri a-c
|
|
||||||
1 (B) smell the uppercase Roses +flowers @outside
|
|
||||||
3 (C) notice the sunflowers
|
|
||||||
--
|
|
||||||
TODO: 2 of 5 tasks shown
|
|
||||||
|
|
||||||
>>> todo.sh -p listpri c-Z
|
|
||||||
3 (C) notice the sunflowers
|
|
||||||
2 (X) clean the house from A-Z
|
|
||||||
4 (X) listen to music
|
|
||||||
--
|
|
||||||
TODO: 3 of 5 tasks shown
|
|
||||||
|
|
||||||
>>> todo.sh -p listpri A-
|
|
||||||
2 (X) clean the house from A-Z
|
|
||||||
--
|
|
||||||
TODO: 1 of 5 tasks shown
|
|
||||||
|
|
||||||
>>> todo.sh -p listpri A-C A-Z
|
|
||||||
--
|
|
||||||
TODO: 0 of 5 tasks shown
|
|
||||||
|
|
||||||
>>> todo.sh -p listpri X A-Z
|
|
||||||
2 (X) clean the house from A-Z
|
|
||||||
--
|
|
||||||
TODO: 1 of 5 tasks shown
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat > todo.txt <<EOF
|
cat > todo.txt <<EOF
|
||||||
(B) ccc xxx this line should be third.
|
(B) ccc xxx this line should be third.
|
||||||
ccc xxx this line should be third.
|
ccc xxx this line should be third.
|
||||||
|
|||||||
@@ -53,18 +53,6 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <<EOF
|
|||||||
TODO: 3 of 3 tasks shown
|
TODO: 3 of 3 tasks shown
|
||||||
EOF
|
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
|
# 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
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
#!/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,9 +85,13 @@ TODO: $HOME/todo.txt archived.
|
|||||||
TODO: 5 of 5 tasks shown
|
TODO: 5 of 5 tasks shown
|
||||||
|
|
||||||
>>> todo.sh report
|
>>> todo.sh report
|
||||||
TODO: $HOME/todo.txt archived.
|
|
||||||
2009-02-13T04:40:00 5 1
|
|
||||||
TODO: Report file updated.
|
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
|
>>> todo.sh append g a
|
||||||
usage: todo.sh append ITEM# "TEXT TO APPEND"
|
usage: todo.sh append ITEM# "TEXT TO APPEND"
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ test_failure_ () {
|
|||||||
test_failure=$(($test_failure + 1))
|
test_failure=$(($test_failure + 1))
|
||||||
say_color error "FAIL $test_count: $1"
|
say_color error "FAIL $test_count: $1"
|
||||||
shift
|
shift
|
||||||
echo "$@"
|
echo "$@" | sed -e 's/^/ /'
|
||||||
test "$immediate" = "" || { trap - EXIT; exit 1; }
|
test "$immediate" = "" || { trap - EXIT; exit 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,9 +199,8 @@ test_debug () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_run_ () {
|
test_run_ () {
|
||||||
eval > output 2>&1 "$1"
|
eval >&3 2>&4 "$1"
|
||||||
eval_ret="$?"
|
eval_ret="$?"
|
||||||
cat >&3 output
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,57 +260,6 @@ test_expect_success () {
|
|||||||
echo >&3 ""
|
echo >&3 ""
|
||||||
}
|
}
|
||||||
|
|
||||||
test_expect_output () {
|
|
||||||
test "$#" = 2 ||
|
|
||||||
error "bug in the test script: not 2 parameters to test-expect-output"
|
|
||||||
if ! test_skip "$@"
|
|
||||||
then
|
|
||||||
say >&3 "expecting success and output: $2"
|
|
||||||
test_run_ "$2"
|
|
||||||
if [ "$?" = 0 -a "$eval_ret" = 0 ]
|
|
||||||
then
|
|
||||||
cmp_output=$(test_cmp expect output)
|
|
||||||
if [ "$?" = 0 ]
|
|
||||||
then
|
|
||||||
test_ok_ "$1"
|
|
||||||
else
|
|
||||||
test_failure_ "$@" "
|
|
||||||
$cmp_output"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
test_failure_ "$@"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo >&3 ""
|
|
||||||
}
|
|
||||||
|
|
||||||
test_expect_code_and_output () {
|
|
||||||
test "$#" = 3 ||
|
|
||||||
error "bug in the test script: not 3 parameters to test-expect-code-and-output"
|
|
||||||
if ! test_skip "$@"
|
|
||||||
then
|
|
||||||
say >&3 "expecting exit code $1 and output: $3"
|
|
||||||
test_run_ "$3"
|
|
||||||
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
|
|
||||||
then
|
|
||||||
cmp_output=$(test_cmp expect output)
|
|
||||||
if [ "$?" = 0 ]
|
|
||||||
then
|
|
||||||
test_ok_ "$2"
|
|
||||||
else
|
|
||||||
test_failure_ "$2" "$3" "
|
|
||||||
$cmp_output"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
cmp_output=$(test_cmp expect output)
|
|
||||||
test_failure_ "$2" "$3" "
|
|
||||||
* expected exit code $1, actual ${eval_ret}${cmp_output:+
|
|
||||||
}${cmp_output}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo >&3 ""
|
|
||||||
}
|
|
||||||
|
|
||||||
test_expect_code () {
|
test_expect_code () {
|
||||||
test "$#" = 3 ||
|
test "$#" = 3 ||
|
||||||
error "bug in the test script: not 3 parameters to test-expect-code"
|
error "bug in the test script: not 3 parameters to test-expect-code"
|
||||||
@@ -323,8 +271,7 @@ test_expect_code () {
|
|||||||
then
|
then
|
||||||
test_ok_ "$2"
|
test_ok_ "$2"
|
||||||
else
|
else
|
||||||
test_failure_ "$2" "$3" "
|
test_failure_ "$@"
|
||||||
* expected exit code $1, actual ${eval_ret}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo >&3 ""
|
echo >&3 ""
|
||||||
@@ -595,9 +542,9 @@ test_todo_session () {
|
|||||||
"")
|
"")
|
||||||
if [ ! -z "$cmd" ]; then
|
if [ ! -z "$cmd" ]; then
|
||||||
if [ $status = 0 ]; then
|
if [ $status = 0 ]; then
|
||||||
test_expect_output "$1 $subnum" "$cmd"
|
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||||
else
|
else
|
||||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
subnum=$(($subnum + 1))
|
subnum=$(($subnum + 1))
|
||||||
@@ -613,9 +560,9 @@ test_todo_session () {
|
|||||||
done
|
done
|
||||||
if [ ! -z "$cmd" ]; then
|
if [ ! -z "$cmd" ]; then
|
||||||
if [ $status = 0 ]; then
|
if [ $status = 0 ]; then
|
||||||
test_expect_output "$1 $subnum" "$cmd"
|
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||||
else
|
else
|
||||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
1
todo.cfg
1
todo.cfg
@@ -8,6 +8,7 @@ export TODO_DIR=`dirname "$0"`
|
|||||||
export TODO_FILE="$TODO_DIR/todo.txt"
|
export TODO_FILE="$TODO_DIR/todo.txt"
|
||||||
export DONE_FILE="$TODO_DIR/done.txt"
|
export DONE_FILE="$TODO_DIR/done.txt"
|
||||||
export REPORT_FILE="$TODO_DIR/report.txt"
|
export REPORT_FILE="$TODO_DIR/report.txt"
|
||||||
|
export TMP_FILE="$TODO_DIR/todo.tmp"
|
||||||
|
|
||||||
# You can customize your actions directory location
|
# You can customize your actions directory location
|
||||||
#export TODO_ACTIONS_DIR="$HOME/.todo.actions.d"
|
#export TODO_ACTIONS_DIR="$HOME/.todo.actions.d"
|
||||||
|
|||||||
246
todo.sh
246
todo.sh
@@ -50,7 +50,6 @@ shorthelp()
|
|||||||
append|app ITEM# "TEXT TO APPEND"
|
append|app ITEM# "TEXT TO APPEND"
|
||||||
archive
|
archive
|
||||||
command [ACTIONS]
|
command [ACTIONS]
|
||||||
deduplicate
|
|
||||||
del|rm ITEM# [TERM]
|
del|rm ITEM# [TERM]
|
||||||
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
||||||
do ITEM#[, ITEM#, ITEM#, ...]
|
do ITEM#[, ITEM#, ITEM#, ...]
|
||||||
@@ -59,7 +58,7 @@ shorthelp()
|
|||||||
listall|lsa [TERM...]
|
listall|lsa [TERM...]
|
||||||
listcon|lsc
|
listcon|lsc
|
||||||
listfile|lf [SRC [TERM...]]
|
listfile|lf [SRC [TERM...]]
|
||||||
listpri|lsp [PRIORITIES] [TERM...]
|
listpri|lsp [PRIORITY] [TERM...]
|
||||||
listproj|lsprj [TERM...]
|
listproj|lsprj [TERM...]
|
||||||
move|mv ITEM# DEST [SRC]
|
move|mv ITEM# DEST [SRC]
|
||||||
prepend|prep ITEM# "TEXT TO PREPEND"
|
prepend|prep ITEM# "TEXT TO PREPEND"
|
||||||
@@ -68,8 +67,6 @@ shorthelp()
|
|||||||
report
|
report
|
||||||
shorthelp
|
shorthelp
|
||||||
|
|
||||||
Actions can be added and overridden using scripts in the actions
|
|
||||||
directory.
|
|
||||||
EndHelp
|
EndHelp
|
||||||
|
|
||||||
# Only list the one-line usage from the add-on actions. This assumes that
|
# Only list the one-line usage from the add-on actions. This assumes that
|
||||||
@@ -90,10 +87,10 @@ help()
|
|||||||
|
|
||||||
Options:
|
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).
|
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).
|
names (default).
|
||||||
-c
|
-c
|
||||||
Color mode
|
Color mode
|
||||||
@@ -106,7 +103,7 @@ help()
|
|||||||
-p
|
-p
|
||||||
Plain mode turns off colors
|
Plain mode turns off colors
|
||||||
-P
|
-P
|
||||||
Hide priority labels in list output. Use twice to show
|
Hide priority labels in list output. Use twice to show
|
||||||
priority labels (default).
|
priority labels (default).
|
||||||
-a
|
-a
|
||||||
Don't auto-archive tasks automatically on completion
|
Don't auto-archive tasks automatically on completion
|
||||||
@@ -165,6 +162,7 @@ help()
|
|||||||
Adds FIRST THING I NEED TO DO to your todo.txt on its own line and
|
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.
|
Adds SECOND THING I NEED TO DO to you todo.txt on its own line.
|
||||||
Project and context notation optional.
|
Project and context notation optional.
|
||||||
|
Quotes optional.
|
||||||
|
|
||||||
addto DEST "TEXT TO ADD"
|
addto DEST "TEXT TO ADD"
|
||||||
Adds a line of text to any file located in the todo.txt directory.
|
Adds a line of text to any file located in the todo.txt directory.
|
||||||
@@ -182,9 +180,6 @@ help()
|
|||||||
Runs the remaining arguments using only todo.sh builtins.
|
Runs the remaining arguments using only todo.sh builtins.
|
||||||
Will not call any .todo.actions.d scripts.
|
Will not call any .todo.actions.d scripts.
|
||||||
|
|
||||||
deduplicate
|
|
||||||
Removes duplicate lines from todo.txt.
|
|
||||||
|
|
||||||
del ITEM# [TERM]
|
del ITEM# [TERM]
|
||||||
rm ITEM# [TERM]
|
rm ITEM# [TERM]
|
||||||
Deletes the task on line ITEM# in todo.txt.
|
Deletes the task on line ITEM# in todo.txt.
|
||||||
@@ -204,19 +199,13 @@ help()
|
|||||||
list [TERM...]
|
list [TERM...]
|
||||||
ls [TERM...]
|
ls [TERM...]
|
||||||
Displays all tasks that contain TERM(s) sorted by priority with line
|
Displays all tasks that contain TERM(s) sorted by priority with line
|
||||||
numbers. Each task must match all TERM(s) (logical AND); to display
|
numbers. If no TERM specified, lists entire todo.txt.
|
||||||
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...]
|
listall [TERM...]
|
||||||
lsa [TERM...]
|
lsa [TERM...]
|
||||||
Displays all the lines in todo.txt AND done.txt that contain TERM(s)
|
Displays all the lines in todo.txt AND done.txt that contain TERM(s)
|
||||||
sorted by priority with line numbers. Hides all tasks that
|
sorted by priority with line numbers. If no TERM specified, lists
|
||||||
contain TERM(s) preceded by a minus sign (i.e. -TERM). If no
|
entire todo.txt AND done.txt concatenated and sorted.
|
||||||
TERM specified, lists entire todo.txt AND done.txt
|
|
||||||
concatenated and sorted.
|
|
||||||
|
|
||||||
listcon
|
listcon
|
||||||
lsc
|
lsc
|
||||||
@@ -226,24 +215,19 @@ help()
|
|||||||
lf [SRC [TERM...]]
|
lf [SRC [TERM...]]
|
||||||
Displays all the lines in SRC file located in the todo.txt directory,
|
Displays all the lines in SRC file located in the todo.txt directory,
|
||||||
sorted by priority with line numbers. If TERM specified, lists
|
sorted by priority with line numbers. If TERM specified, lists
|
||||||
all lines that contain TERM(s) in SRC file. Hides all tasks that
|
all lines that contain TERM in SRC file.
|
||||||
contain TERM(s) preceded by a minus sign (i.e. -TERM).
|
|
||||||
Without any arguments, the names of all text files in the todo.txt
|
Without any arguments, the names of all text files in the todo.txt
|
||||||
directory are listed.
|
directory are listed.
|
||||||
|
|
||||||
listpri [PRIORITIES] [TERM...]
|
listpri [PRIORITY] [TERM...]
|
||||||
lsp [PRIORITIES] [TERM...]
|
lsp [PRIORITY] [TERM...]
|
||||||
Displays all tasks prioritized PRIORITIES.
|
Displays all tasks prioritized PRIORITY.
|
||||||
PRIORITIES can be a single one (A) or a range (A-C).
|
If no PRIORITY specified, lists all prioritized tasks.
|
||||||
If no PRIORITIES 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
|
listproj
|
||||||
lsprj
|
lsprj
|
||||||
Lists all the projects (terms that start with a + sign) in
|
Lists all the projects that start with the + sign in todo.txt.
|
||||||
todo.txt.
|
|
||||||
|
|
||||||
move ITEM# DEST [SRC]
|
move ITEM# DEST [SRC]
|
||||||
mv ITEM# DEST [SRC]
|
mv ITEM# DEST [SRC]
|
||||||
@@ -261,7 +245,7 @@ help()
|
|||||||
p ITEM# PRIORITY
|
p ITEM# PRIORITY
|
||||||
Adds PRIORITY to task on line ITEM#. If the task is already
|
Adds PRIORITY to task on line ITEM#. If the task is already
|
||||||
prioritized, replaces current priority with new PRIORITY.
|
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"
|
replace ITEM# "UPDATED TODO"
|
||||||
Replaces task on line ITEM# with UPDATED TODO.
|
Replaces task on line ITEM# with UPDATED TODO.
|
||||||
@@ -272,6 +256,7 @@ help()
|
|||||||
shorthelp
|
shorthelp
|
||||||
List the one-line usage of all built-in and add-on actions.
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
|
||||||
|
|
||||||
EndActionsHelp
|
EndActionsHelp
|
||||||
|
|
||||||
addonHelp
|
addonHelp
|
||||||
@@ -303,6 +288,12 @@ die()
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup()
|
||||||
|
{
|
||||||
|
[ -f "$TMP_FILE" ] && rm "$TMP_FILE"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
cleaninput()
|
cleaninput()
|
||||||
{
|
{
|
||||||
# Parameters: When $1 = "for sed", performs additional escaping for use
|
# Parameters: When $1 = "for sed", performs additional escaping for use
|
||||||
@@ -362,6 +353,20 @@ getNewtodo()
|
|||||||
[ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item."
|
[ -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()
|
replaceOrPrepend()
|
||||||
{
|
{
|
||||||
action=$1; shift
|
action=$1; shift
|
||||||
@@ -665,6 +670,7 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
|||||||
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
||||||
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
|
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
|
||||||
|
|
||||||
|
[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
|
||||||
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
||||||
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
||||||
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
||||||
@@ -754,32 +760,13 @@ _list() {
|
|||||||
## Get our search arguments, if any
|
## Get our search arguments, if any
|
||||||
shift ## was file name, new $1 is first search term
|
shift ## was file name, new $1 is first search term
|
||||||
|
|
||||||
_format "$src" '' "$@"
|
## Build the filter.
|
||||||
|
filter_command=$(filtercommand "${pre_filter_command:-}" "${post_filter_command:-}" "$@")
|
||||||
|
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
## Figure out how much padding we need to use
|
||||||
echo "--"
|
## We need one level of padding for each power of 10 $LINES uses
|
||||||
echo "$(getPrefix "$src"): ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
LINES=$( sed -n '$ =' "$src" )
|
||||||
fi
|
PADDING=${#LINES}
|
||||||
}
|
|
||||||
getPadding()
|
|
||||||
{
|
|
||||||
## We need one level of padding for each power of 10 $LINES uses.
|
|
||||||
LINES=$(sed -n '$ =' "${1:-$TODO_FILE}")
|
|
||||||
printf %s ${#LINES}
|
|
||||||
}
|
|
||||||
_format()
|
|
||||||
{
|
|
||||||
# Parameters: $1: todo input file; when empty formats stdin
|
|
||||||
# $2: ITEM# number width; if empty auto-detects from $1 / $TODO_FILE.
|
|
||||||
# Precondition: None
|
|
||||||
# Postcondition: $NUMTASKS and $TOTALTASKS contain statistics (unless $TODOTXT_VERBOSE=0).
|
|
||||||
|
|
||||||
FILE=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
## Figure out how much padding we need to use, unless this was passed to us.
|
|
||||||
PADDING=${1:-$(getPadding "$FILE")}
|
|
||||||
shift
|
|
||||||
|
|
||||||
## Number the file, then run the filter command,
|
## Number the file, then run the filter command,
|
||||||
## then sort and mangle output some more
|
## then sort and mangle output some more
|
||||||
@@ -787,21 +774,14 @@ _format()
|
|||||||
TODOTXT_FINAL_FILTER="cat"
|
TODOTXT_FINAL_FILTER="cat"
|
||||||
fi
|
fi
|
||||||
items=$(
|
items=$(
|
||||||
if [ "$FILE" ]; then
|
sed = "$src" \
|
||||||
sed = "$FILE"
|
| sed '''
|
||||||
else
|
|
||||||
sed =
|
|
||||||
fi \
|
|
||||||
| sed -e '''
|
|
||||||
N
|
N
|
||||||
s/^/ /
|
s/^/ /
|
||||||
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
|
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
|
||||||
/^[ 0-9]\{1,\} *$/d
|
/^[ 0-9]\+ *$/d
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
## Build and apply the filter.
|
|
||||||
filter_command=$(filtercommand "${pre_filter_command:-}" "${post_filter_command:-}" "$@")
|
|
||||||
if [ "${filter_command}" ]; then
|
if [ "${filter_command}" ]; then
|
||||||
filtered_items=$(echo -n "$items" | eval "${filter_command}")
|
filtered_items=$(echo -n "$items" | eval "${filter_command}")
|
||||||
else
|
else
|
||||||
@@ -826,7 +806,7 @@ _format()
|
|||||||
{
|
{
|
||||||
if (match($0, /^[0-9]+ x /)) {
|
if (match($0, /^[0-9]+ x /)) {
|
||||||
print highlight("COLOR_DONE") $0 highlight("DEFAULT")
|
print highlight("COLOR_DONE") $0 highlight("DEFAULT")
|
||||||
} else if (match($0, /^[0-9]+ \([A-Z]\) /)) {
|
} else if (match($0, /^[0-9]+ \([A-Z]\)[[:space:]]/)) {
|
||||||
clr = highlight("PRI_" substr($0, RSTART + RLENGTH - 3, 1))
|
clr = highlight("PRI_" substr($0, RSTART + RLENGTH - 3, 1))
|
||||||
print \
|
print \
|
||||||
(clr ? clr : highlight("PRI_X")) \
|
(clr ? clr : highlight("PRI_X")) \
|
||||||
@@ -836,9 +816,8 @@ _format()
|
|||||||
}
|
}
|
||||||
''' \
|
''' \
|
||||||
| sed '''
|
| sed '''
|
||||||
s/'"${HIDE_PROJECTS_SUBSTITUTION:-^}"'//g
|
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||||
s/'"${HIDE_CONTEXTS_SUBSTITUTION:-^}"'//g
|
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||||
s/'"${HIDE_CUSTOM_SUBSTITUTION:-^}"'//g
|
|
||||||
''' \
|
''' \
|
||||||
| eval ${TODOTXT_FINAL_FILTER} \
|
| eval ${TODOTXT_FINAL_FILTER} \
|
||||||
)
|
)
|
||||||
@@ -847,13 +826,16 @@ _format()
|
|||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
||||||
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
||||||
|
|
||||||
|
echo "--"
|
||||||
|
echo "$(getPrefix "$FILE"): ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||||
fi
|
fi
|
||||||
if [ $TODOTXT_VERBOSE -gt 1 ]; then
|
if [ $TODOTXT_VERBOSE -gt 1 ]; then
|
||||||
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list getPadding _format die
|
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list die
|
||||||
|
|
||||||
# == HANDLE ACTION ==
|
# == HANDLE ACTION ==
|
||||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||||
@@ -871,7 +853,9 @@ then
|
|||||||
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
|
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
|
||||||
then
|
then
|
||||||
"$TODO_ACTIONS_DIR/$action" "$@"
|
"$TODO_ACTIONS_DIR/$action" "$@"
|
||||||
exit $?
|
status=$?
|
||||||
|
cleanup
|
||||||
|
exit $status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Only run if $action isn't found in .todo.actions.d
|
## Only run if $action isn't found in .todo.actions.d
|
||||||
@@ -953,15 +937,7 @@ case $action in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"archive" )
|
"archive" )
|
||||||
# defragment blank lines
|
archive;;
|
||||||
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" )
|
"del" | "rm" )
|
||||||
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||||
@@ -1019,7 +995,7 @@ case $action in
|
|||||||
|
|
||||||
# Split multiple depri's, if comma separated change to whitespace separated
|
# Split multiple depri's, if comma separated change to whitespace separated
|
||||||
# Loop the 'depri' function for each item
|
# Loop the 'depri' function for each item
|
||||||
for item in ${*//,/ }; do
|
for item in $(echo $* | tr ',' ' '); do
|
||||||
getTodo "$item"
|
getTodo "$item"
|
||||||
|
|
||||||
if [[ "$todo" = \(?\)\ * ]]; then
|
if [[ "$todo" = \(?\)\ * ]]; then
|
||||||
@@ -1043,7 +1019,7 @@ case $action in
|
|||||||
|
|
||||||
# Split multiple do's, if comma separated change to whitespace separated
|
# Split multiple do's, if comma separated change to whitespace separated
|
||||||
# Loop the 'do' function for each item
|
# Loop the 'do' function for each item
|
||||||
for item in ${*//,/ }; do
|
for item in $(echo $* | tr ',' ' '); do
|
||||||
getTodo "$item"
|
getTodo "$item"
|
||||||
|
|
||||||
# Check if this item has already been done
|
# Check if this item has already been done
|
||||||
@@ -1063,9 +1039,7 @@ case $action in
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
# Recursively invoke the script to allow overriding of the archive
|
archive
|
||||||
# action.
|
|
||||||
"$TODO_FULL_SH" archive
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -1097,21 +1071,8 @@ case $action in
|
|||||||
"listall" | "lsa" )
|
"listall" | "lsa" )
|
||||||
shift ## Was lsa; new $1 is first search term
|
shift ## Was lsa; new $1 is first search term
|
||||||
|
|
||||||
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||||
PADDING=${#TOTAL}
|
_list "$TMP_FILE" "$@"
|
||||||
|
|
||||||
post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=$PADDING '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
|
|
||||||
cat "$TODO_FILE" "$DONE_FILE" | TODOTXT_VERBOSE=0 _format '' "$PADDING" "$@"
|
|
||||||
|
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
|
||||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
|
||||||
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$TODO_FILE" 1 "$@" | sed -n '$ =')
|
|
||||||
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$DONE_FILE" 1 "$@" | 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
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"listfile" | "lf" )
|
"listfile" | "lf" )
|
||||||
@@ -1139,8 +1100,8 @@ case $action in
|
|||||||
"listpri" | "lsp" )
|
"listpri" | "lsp" )
|
||||||
shift ## was "listpri", new $1 is priority to list or first TERM
|
shift ## was "listpri", new $1 is priority to list or first TERM
|
||||||
|
|
||||||
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep -e '^[A-Z]$' -e '^[A-Z]-[A-Z]$') && shift || pri="A-Z"
|
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$') && shift || pri="[A-Z]"
|
||||||
post_filter_command="grep '^ *[0-9]\+ ([${pri}]) '"
|
post_filter_command="grep '^ *[0-9]\+ (${pri}) '"
|
||||||
_list "$TODO_FILE" "$@"
|
_list "$TODO_FILE" "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -1230,71 +1191,26 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"report" )
|
"report" )
|
||||||
# archive first
|
#archive first
|
||||||
# Recursively invoke the script to allow overriding of the archive
|
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
||||||
# action.
|
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||||
"$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" )
|
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||||
NEWDATA="${TOTAL:-0} ${TDONE:-0}"
|
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
|
||||||
LASTREPORT=$(sed -ne '$p' "$REPORT_FILE")
|
echo ${TDONE:-0})
|
||||||
LASTDATA=${LASTREPORT#* } # Strip timestamp.
|
echo $TECHO >> "$REPORT_FILE"
|
||||||
if [ "$LASTDATA" = "$NEWDATA" ]; then
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||||
echo "$LASTREPORT"
|
cat "$REPORT_FILE"
|
||||||
[ $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
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
* )
|
* )
|
||||||
usage;;
|
usage;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|||||||
@@ -38,28 +38,20 @@ _todo()
|
|||||||
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
|
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
|
||||||
@*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);;
|
@*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);;
|
||||||
*) if [[ "$cur" =~ ^[0-9]+$ ]]; then
|
*) 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
|
# Remove the (padded) task number; we prepend the
|
||||||
# user-provided $cur instead.
|
# user-provided $cur.
|
||||||
# Remove the timestamp prepended by the -t option,
|
item=${item#* }
|
||||||
# and the done date (for done tasks); there's no
|
|
||||||
# todo.txt option for that yet.
|
# Remove the timestamp prepended by the -t option;
|
||||||
# But keep priority and "x"; they're short and may
|
# there's no todo.txt option for that yet.
|
||||||
# provide useful context.
|
item=${item#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] }
|
||||||
# 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
|
# Append task text as a shell comment. This
|
||||||
# completion can be a safety check before a
|
# completion can be a safety check before a
|
||||||
# destructive todo.txt operation.
|
# destructive todo.txt operation.
|
||||||
[ "$todo" ] && COMPREPLY[0]="$cur # $todo"
|
[ "$item" ] && COMPREPLY[0]="$cur # $item"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user