Merge pull request #82 from inkarkat/listcon-filters

Accept filters for listcon, too.
This commit is contained in:
Gina Trapani
2012-05-11 09:41:56 -07:00
2 changed files with 31 additions and 12 deletions

View File

@@ -55,6 +55,16 @@ test_todo_session 'listcon e-mail address test' <<EOF
@con02 @con02
EOF EOF
cat > todo.txt <<EOF
(B) smell the uppercase Roses +roses @outside +shared
(C) notice the sunflowers +sunflowers @garden +shared +landscape
stop
EOF
test_todo_session 'listcon with project' <<EOF
>>> todo.sh listcon +landscape
@garden
EOF
cat > todo.txt <<EOF cat > todo.txt <<EOF
@con01 -- Some context 1 task @con01 -- Some context 1 task
EOF EOF

33
todo.sh
View File

@@ -58,7 +58,7 @@ shorthelp()
list|ls [TERM...] list|ls [TERM...]
listall|lsa [TERM...] listall|lsa [TERM...]
listaddons listaddons
listcon|lsc listcon|lsc [TERM...]
listfile|lf [SRC [TERM...]] listfile|lf [SRC [TERM...]]
listpri|lsp [PRIORITIES] [TERM...] listpri|lsp [PRIORITIES] [TERM...]
listproj|lsprj [TERM...] listproj|lsprj [TERM...]
@@ -223,9 +223,10 @@ help()
listaddons listaddons
Lists all added and overridden actions in the actions directory. Lists all added and overridden actions in the actions directory.
listcon listcon [TERM...]
lsc lsc [TERM...]
Lists all the task contexts that start with the @ sign in todo.txt. Lists all the task contexts that start with the @ sign in todo.txt.
If TERM specified, considers only tasks that contain TERM(s).
listfile [SRC [TERM...]] listfile [SRC [TERM...]]
lf [SRC [TERM...]] lf [SRC [TERM...]]
@@ -245,10 +246,11 @@ help()
Hides all tasks that contain TERM(s) preceded by a minus sign Hides all tasks that contain TERM(s) preceded by a minus sign
(i.e. -TERM). (i.e. -TERM).
listproj listproj [TERM...]
lsprj lsprj [TERM...]
Lists all the projects (terms that start with a + sign) in Lists all the projects (terms that start with a + sign) in
todo.txt. todo.txt.
If TERM specified, considers only tasks that contain TERM(s).
move ITEM# DEST [SRC] move ITEM# DEST [SRC]
mv ITEM# DEST [SRC] mv ITEM# DEST [SRC]
@@ -859,7 +861,17 @@ _format()
fi fi
} }
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list getPadding _format die listWordsWithSigil()
{
sigil=$1
shift
FILE=$TODO_FILE
[ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR"
eval "$(filtercommand 'cat "${FILE[@]}"' '' "$@")" | grep -o "[^ ]*${sigil}[^ ]\\+" | grep "^$sigil" | sort -u
}
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format 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' )
@@ -1134,16 +1146,13 @@ case $action in
;; ;;
"listcon" | "lsc" ) "listcon" | "lsc" )
FILE=$TODO_FILE shift
[ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR" listWordsWithSigil '@' "$@"
grep -ho '[^ ]*@[^ ]\+' "${FILE[@]}" | grep '^@' | sort -u
;; ;;
"listproj" | "lsprj" ) "listproj" | "lsprj" )
FILE=$TODO_FILE
[ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR"
shift shift
eval "$(filtercommand 'cat "${FILE[@]}"' '' "$@")" | grep -o '[^ ]*+[^ ]\+' | grep '^+' | sort -u listWordsWithSigil '+' "$@"
;; ;;
"listpri" | "lsp" ) "listpri" | "lsp" )