Hiding Priority, Context, and Project
. Adds three new switches that hide priorty, context, and project text in list output. . Changes proposed by Dave Hein. Original patch by Dave Hein. Revised patch by David A. Harding. Thread starts at http://tech.groups.yahoo.com/group/todotxt/message/1848
This commit is contained in:
92
todo.sh
92
todo.sh
@@ -119,6 +119,12 @@ help()
|
|||||||
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
-@
|
||||||
|
Hide context names in list output. Use twice to show context
|
||||||
|
names (default).
|
||||||
|
-+
|
||||||
|
Hide project names in list output. Use twice to show project
|
||||||
|
names (default).
|
||||||
-d CONFIG_FILE
|
-d CONFIG_FILE
|
||||||
Use a configuration file other than the default ~/todo.cfg
|
Use a configuration file other than the default ~/todo.cfg
|
||||||
-f
|
-f
|
||||||
@@ -127,6 +133,9 @@ help()
|
|||||||
Display this help message
|
Display this help message
|
||||||
-p
|
-p
|
||||||
Plain mode turns off colors
|
Plain mode turns off colors
|
||||||
|
-P
|
||||||
|
Hide priority labels in list output. Use twice to show
|
||||||
|
priority labels (default).
|
||||||
-a
|
-a
|
||||||
Don't auto-archive tasks automatically on completion
|
Don't auto-archive tasks automatically on completion
|
||||||
-n
|
-n
|
||||||
@@ -195,9 +204,50 @@ PRESERVE_LINE_NUMBERS=1
|
|||||||
AUTO_ARCHIVE=1
|
AUTO_ARCHIVE=1
|
||||||
DATE_ON_ADD=0
|
DATE_ON_ADD=0
|
||||||
|
|
||||||
while getopts ":fhpnatvVd:" Option
|
while getopts ":fhpnatvV+@Pd:" Option
|
||||||
do
|
do
|
||||||
case $Option in
|
case $Option in
|
||||||
|
'@' )
|
||||||
|
## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_CONTEXT_NAMES++ ))
|
||||||
|
if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show context names
|
||||||
|
unset HIDE_CONTEXTS_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide context names
|
||||||
|
#
|
||||||
|
## Match: \(^\|[[:space:]] beginning of line or a space
|
||||||
|
## @ literal context label
|
||||||
|
## [^[:space:]]\+ Anything besides whitespace one
|
||||||
|
## or more times
|
||||||
|
HIDE_CONTEXTS_SUBSTITUTION="\(^\|[[:space:]]\)@[^[:space:]]\+"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
'+' )
|
||||||
|
## HIDE_PROJECT_NAMES starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_PROJECT_NAMES++ ))
|
||||||
|
if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show project names
|
||||||
|
unset HIDE_PROJECTS_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide project names
|
||||||
|
## Match: \(^\|[[:space:]] beginning of line or a space
|
||||||
|
## @ literal context label
|
||||||
|
## [^[:space:]]\+ Anything besides whitespace one
|
||||||
|
## or more times
|
||||||
|
HIDE_PROJECTS_SUBSTITUTION="\(^\|[[:space:]]\)+[^[:space:]]\+"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
a )
|
a )
|
||||||
AUTO_ARCHIVE=0
|
AUTO_ARCHIVE=0
|
||||||
;;
|
;;
|
||||||
@@ -216,6 +266,22 @@ do
|
|||||||
p )
|
p )
|
||||||
PLAIN=1
|
PLAIN=1
|
||||||
;;
|
;;
|
||||||
|
P )
|
||||||
|
## HIDE_PRIORITY_LABELS starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_PRIORITY_LABELS++ ))
|
||||||
|
if [ $(( $HIDE_PRIORITY_LABELS % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show priority labels
|
||||||
|
unset HIDE_PRIORITY_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide priority labels
|
||||||
|
HIDE_PRIORITY_SUBSTITUTION="([A-Z])[[:space:]]"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
t )
|
t )
|
||||||
DATE_ON_ADD=1
|
DATE_ON_ADD=1
|
||||||
;;
|
;;
|
||||||
@@ -414,8 +480,22 @@ case $action in
|
|||||||
"list" | "ls" )
|
"list" | "ls" )
|
||||||
item=$2
|
item=$2
|
||||||
if [ -z "$item" ]; then
|
if [ -z "$item" ]; then
|
||||||
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`"
|
|
||||||
echo "--"
|
echo "--"
|
||||||
|
echo -e "$( \
|
||||||
|
sed = "$TODO_FILE" \
|
||||||
|
| sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' \
|
||||||
|
| sed 's/^ /0/' \
|
||||||
|
| sort -f -k2 \
|
||||||
|
| sed '/^[0-9][0-9] x /! {
|
||||||
|
s/\(.*(A).*\)/'$PRI_A'\1 '$DEFAULT'/g;
|
||||||
|
s/\(.*(B).*\)/'$PRI_B'\1 '$DEFAULT'/g;
|
||||||
|
s/\(.*(C).*\)/'$PRI_C'\1 '$DEFAULT'/g;
|
||||||
|
s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/g;
|
||||||
|
}' \
|
||||||
|
| sed 's/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
)"
|
||||||
NUMTASKS=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
NUMTASKS=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
||||||
echo "TODO: $NUMTASKS tasks in $TODO_FILE."
|
echo "TODO: $NUMTASKS tasks in $TODO_FILE."
|
||||||
else
|
else
|
||||||
@@ -445,7 +525,13 @@ case $action in
|
|||||||
do
|
do
|
||||||
command=`echo "$command" | grep -i $i `
|
command=`echo "$command" | grep -i $i `
|
||||||
done
|
done
|
||||||
command=`echo "$command" | sort -f -k2`
|
command=$( \
|
||||||
|
echo "$command" \
|
||||||
|
| sort -f -k2 \
|
||||||
|
| sed 's/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
)
|
||||||
echo -e "$command"
|
echo -e "$command"
|
||||||
fi
|
fi
|
||||||
cleanup ;;
|
cleanup ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user