Generalizes the PRI_X color support to all priorities.

It allows you to assign a distinct color to any priority, not just A, B and C. Submitted to the todo.txt mailing list on 3-Jun-2010; committed on behalf of the author because there was no follow-up; cp. http://tech.groups.yahoo.com/group/todotxt/message/2619
Also committed this because it fixes a sed expression error when there are spaces in a $PRI_... variable, which occurred in my integration with Conky.
Note: This commit obsoletes and replaces the previous fix to colorization in commit 8b7e2e6aad.
Added tests for highlighting of priorities.
This commit is contained in:
Glyn Faulkner
2010-06-21 15:25:42 +02:00
committed by Ingo Karkat
parent 0b16bae2e8
commit e7b5841721
2 changed files with 125 additions and 11 deletions

22
todo.sh
View File

@@ -460,9 +460,9 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
if [ $TODOTXT_PLAIN = 1 ]; then
PRI_A=$NONE
PRI_B=$NONE
PRI_C=$NONE
for clr in ${!PRI_@}; do
export $clr=$NONE
done
PRI_X=$NONE
DEFAULT=$NONE
fi
@@ -570,14 +570,14 @@ _list() {
s/^ /0/;
''' \
| eval ${TODOTXT_SORT_COMMAND} \
| sed '''
/^[0-9]\{'$PADDING'\} x /! {
/(A)/ s|^.*|'$PRI_A'&'$DEFAULT'|
/(B)/ s|^.*|'$PRI_B'&'$DEFAULT'|
/(C)/ s|^.*|'$PRI_C'&'$DEFAULT'|
/([D-Z])/ s|^.*|'$PRI_X'&'$DEFAULT'|
}
''' \
| awk '''{
pos = match($0, /\([A-Z]\)/)
if( pos > 0 && match($0, /^[0-9]+ x /) != 1 ) {
clr=ENVIRON["PRI_" substr($0, pos+1, 1)]
str = ( clr ? clr : ENVIRON["PRI_X"] ) $0 ENVIRON["DEFAULT"]
gsub( /\\+033/, "\033", str) ; print str
} else { print }
}''' \
| sed '''
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g