Compare commits

...

5 Commits

Author SHA1 Message Date
Ingo Karkat
e3fce6f12b Revert to safer POSIX AWK regexp.
AWK from Ubuntu 8.04 (mawk) doesn't support [[:space:]]; so for backwards compatibility use a plain ASCII space instead.
2011-11-03 18:37:36 +01:00
Ingo Karkat
227b9d2c0a BUG: Pattern "(X) " anywhere hidden with -P.
The regular expression HIDE_PRIORITY_SUBSTITUTION is not anchored, so strings that look like a priority but are not at the beginning are filtered, too.
Anchoring the regexp in the step after the highlighting has been applied is problematic due to the prepended dynamic priority highlighting string, and it also cannot be done before that because highlighting needs the information. Therefore, the filtering is moved into the AWK highlighting itself.
2011-09-23 16:27:30 +02:00
Ingo Karkat
99fa15da36 BUG: Pattern "(X)" anywhere highlighted as prioritized.
According to the "Todo.txt Format" specs, "Rule 1: If a priority exists, it ALWAYS appears first."

Adapt AWK filtering to match priorities only directly after the task number added by the _list processing, and also matching the required trailing space.
2011-09-23 15:40:23 +02:00
Ingo Karkat
72fe73f3d8 nobacktick test: Use literal backtick
* Fix sed error on Mac OS, also ignore entire commented lines.
* With proper quoting, the non-POSIX \d96 escape isn't necessary, and the check should work also on Mac OS.
2011-08-04 10:15:54 -07:00
Ingo Karkat
8f6070e702 Re-applying the listpri stuff still missing from the pull requests. 2011-07-10 22:04:51 +02:00
6 changed files with 91 additions and 53 deletions

View File

@@ -5,11 +5,12 @@ test_description='no old-style backtick command substitution
This test checks the todo.sh script itself for occurrences
of old-style backtick command substitution, which should be
replaced with $(...).
On failure, it will print each offending line number and line.
'
. ./test-lib.sh
test_todo_session 'no old-style backtick command substitution' <<EOF
>>> sed -n -e 's/[ \t]#.*//' -e '/\d96/{=;p}' "$(which todo.sh)"
>>> sed -n -e 's/\(^\|[ \t]\)#.*//' -e '/\`/{' -e '=;p' -e '}' "$(which todo.sh)"
EOF
test_done

View File

@@ -53,6 +53,25 @@ TODO: 2 prioritized (C).
--
TODO: 3 of 3 tasks shown
>>> todo.sh add "smell the coffee +wakeup"
4 smell the coffee +wakeup
TODO: 4 added.
>>> todo.sh -p list
1 (B) smell the uppercase Roses +flowers @outside
2 (C) notice the sunflowers
4 smell the coffee +wakeup
3 stop
--
TODO: 4 of 4 tasks shown
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(C) notice the sunflowers
stop
EOF
test_todo_session 'reprioritize' <<EOF
>>> todo.sh pri 2 A
2 (A) notice the sunflowers
TODO: 2 re-prioritized from (C) to (A).
@@ -68,23 +87,11 @@ TODO: 3 of 3 tasks shown
2 (A) notice the sunflowers
TODO: 2 already prioritized (A).
>>> todo.sh -p listpri
2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside
--
TODO: 2 of 3 tasks shown
>>> todo.sh add "smell the coffee +wakeup"
4 smell the coffee +wakeup
TODO: 4 added.
>>> todo.sh -p list
2 (A) notice the sunflowers
1 (B) smell the uppercase Roses +flowers @outside
4 smell the coffee +wakeup
3 stop
--
TODO: 4 of 4 tasks shown
TODO: 3 of 3 tasks shown
EOF
test_done

View File

@@ -4,13 +4,6 @@ test_description='list priority functionality
'
. ./test-lib.sh
test_todo_session 'listpri usage' <<EOF
>>> todo.sh listpri ?
usage: todo.sh listpri PRIORITY
note: PRIORITY must a single letter from A to Z.
=== 1
EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(C) notice the sunflowers
@@ -42,7 +35,7 @@ cat > todo.txt <<EOF
(n) not a prioritized task
notice the (C)opyright
EOF
test_todo_session 'listpri filtering' <<EOF
test_todo_session 'listpri filtering priorities' <<EOF
>>> todo.sh -p listpri
1 (B) smell the uppercase Roses +flowers @outside
2 (C) notice the sunflowers
@@ -68,4 +61,35 @@ TODO: 0 of 5 tasks shown
TODO: 0 of 5 tasks shown
EOF
cat > todo.txt <<EOF
(B) ccc xxx this line should be third.
ccc xxx this line should be third.
(A) aaa zzz this line should be first.
aaa zzz this line should be first.
(B) bbb yyy this line should be second.
bbb yyy this line should be second.
EOF
test_todo_session 'listpri filtering of TERM' <<EOF
>>> todo.sh -p listpri "should be"
3 (A) aaa zzz this line should be first.
5 (B) bbb yyy this line should be second.
1 (B) ccc xxx this line should be third.
--
TODO: 3 of 6 tasks shown
>>> todo.sh -p listpri a "should be"
3 (A) aaa zzz this line should be first.
--
TODO: 1 of 6 tasks shown
>>> todo.sh -p listpri b second
5 (B) bbb yyy this line should be second.
--
TODO: 1 of 6 tasks shown
>>> todo.sh -p listpri x "should be"
--
TODO: 0 of 6 tasks shown
EOF
test_done

View File

@@ -142,7 +142,7 @@ cat > todo.txt <<EOF
(D) @con02 +prj03 -- Some project 03 task, pri D
(D) @con02 +prj04 -- Some project 04 task, pri D
@con01 +prj01 -- Some project 01 task, no priority
@con01 +prj02 -- Some project 02 task, no priority
@con01 +prj02 -- Some project(S) 02 task, no priority
@con02 +prj03 -- Some project 03 task, no priorty
@con02 +prj04 -- Some project 04 task, no priority
EOF
@@ -165,7 +165,7 @@ test_todo_session 'plain mode option' <<EOF
15 (D) @con02 +prj03 -- Some project 03 task, pri D
16 (D) @con02 +prj04 -- Some project 04 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
19 @con02 +prj03 -- Some project 03 task, no priorty
20 @con02 +prj04 -- Some project 04 task, no priority
--
@@ -189,7 +189,7 @@ TODO: 20 of 20 tasks shown
15 (D) @con02 +prj03 -- Some project 03 task, pri D
16 (D) @con02 +prj04 -- Some project 04 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
19 @con02 +prj03 -- Some project 03 task, no priorty
20 @con02 +prj04 -- Some project 04 task, no priority
--
@@ -217,7 +217,7 @@ cat > todo.txt <<EOF
(D) @con02 +prj03 -- Some project 03 task, pri D
(D) @con02 +prj04 -- Some project 04 task, pri D
@con01 +prj01 -- Some project 01 task, no priority
@con01 +prj02 -- Some project 02 task, no priority
@con01 +prj02 -- Some project(S) 02 task, no priority
@con02 +prj03 -- Some project 03 task, no priorty
@con02 +prj04 -- Some project 04 task, no priority
EOF
@@ -240,7 +240,7 @@ test_todo_session 'context, project, and priority suppression' <<EOF
15 (D) @con02 +prj03 -- Some project 03 task, pri D
16 (D) @con02 +prj04 -- Some project 04 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
19 @con02 +prj03 -- Some project 03 task, no priorty
20 @con02 +prj04 -- Some project 04 task, no priority
--
@@ -256,7 +256,7 @@ TODO: 20 of 20 tasks shown
13 (D) @con01 +prj01 -- Some project 01 task, pri D
14 (D) @con01 +prj02 -- Some project 02 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -270,7 +270,7 @@ TODO: 10 of 20 tasks shown
13 @con01 +prj01 -- Some project 01 task, pri D
14 @con01 +prj02 -- Some project 02 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -284,7 +284,7 @@ TODO: 10 of 20 tasks shown
13 (D) @con01 -- Some project 01 task, pri D
14 (D) @con01 -- Some project 02 task, pri D
17 @con01 -- Some project 01 task, no priority
18 @con01 -- Some project 02 task, no priority
18 @con01 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -298,7 +298,7 @@ TODO: 10 of 20 tasks shown
13 (D) +prj01 -- Some project 01 task, pri D
14 (D) +prj02 -- Some project 02 task, pri D
17 +prj01 -- Some project 01 task, no priority
18 +prj02 -- Some project 02 task, no priority
18 +prj02 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -312,7 +312,7 @@ TODO: 10 of 20 tasks shown
13 +prj01 -- Some project 01 task, pri D
14 +prj02 -- Some project 02 task, pri D
17 +prj01 -- Some project 01 task, no priority
18 +prj02 -- Some project 02 task, no priority
18 +prj02 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -326,7 +326,7 @@ TODO: 10 of 20 tasks shown
13 (D) @con01 +prj01 -- Some project 01 task, pri D
14 (D) @con01 +prj02 -- Some project 02 task, pri D
17 @con01 +prj01 -- Some project 01 task, no priority
18 @con01 +prj02 -- Some project 02 task, no priority
18 @con01 +prj02 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
@@ -340,7 +340,7 @@ TODO: 10 of 20 tasks shown
13 -- Some project 01 task, pri D
14 -- Some project 02 task, pri D
17 -- Some project 01 task, no priority
18 -- Some project 02 task, no priority
18 -- Some project(S) 02 task, no priority
--
TODO: 10 of 20 tasks shown
EOF

View File

@@ -166,4 +166,20 @@ test_todo_session 'highlighting with hidden contexts/projects' <<EOF
TODO: 4 of 4 tasks shown
EOF
# check that priorities are only matched at the start of the task
#
cat > todo.txt <<EOF
(D) some prioritized task
not prioritized
should not be seen as PRIORITIZE(D) task
EOF
test_todo_session 'highlighting priority position' <<EOF
>>> todo.sh ls
1 (D) some prioritized task
2 not prioritized
3 should not be seen as PRIORITIZE(D) task
--
TODO: 3 of 3 tasks shown
EOF
test_done

28
todo.sh
View File

@@ -720,17 +720,18 @@ _list() {
return color
}
{
pos = match($0, /\([A-Z]\)/)
if (match($0, /^[0-9]+ x /)) {
print highlight("COLOR_DONE") $0 highlight("DEFAULT")
} else if (pos > 0) {
clr = highlight("PRI_" substr($0, pos+1, 1))
print ( clr ? clr : highlight("PRI_X") ) $0 highlight("DEFAULT")
} else if (match($0, /^[0-9]+ \([A-Z]\) /)) {
clr = highlight("PRI_" substr($0, RSTART + RLENGTH - 3, 1))
print \
(clr ? clr : highlight("PRI_X")) \
(ENVIRON["HIDE_PRIORITY_SUBSTITUTION"] == "" ? $0 : substr($0, 1, RLENGTH - 4) substr($0, RSTART + RLENGTH)) \
highlight("DEFAULT")
} else { print }
}
''' \
| sed '''
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
''' \
@@ -923,7 +924,7 @@ case $action in
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "TODO: No task $item."
if sed "$item!d" "$TODO_FILE" | grep "^(.) " > /dev/null; then
if [[ "$todo" = \(?\)\ * ]]; then
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
NEWTODO=$(sed "$item!d" "$TODO_FILE")
@@ -944,7 +945,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 $(echo $* | tr ',' ' '); do
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
@@ -1013,18 +1014,7 @@ case $action in
"listpri" | "lsp" )
shift ## was "listpri", new $1 is priority to list or first TERM
if [ "${1:-}" ]
then
## A priority was specified
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
die "usage: $TODO_SH listpri PRIORITY
note: PRIORITY must a single letter from A to Z."
}
else
## No priority specified; show all priority tasks
pri="[A-Z]"
fi
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$') && shift || pri="[A-Z]"
post_filter_command="grep '^ *[0-9]\+ (${pri}) '"
_list "$TODO_FILE" "$@"
;;