Merge branch 'master' of git://github.com/ginatrapani/todo.txt-cli
This commit is contained in:
127
todo.sh
127
todo.sh
@@ -49,6 +49,10 @@ help()
|
|||||||
archive
|
archive
|
||||||
Moves done items from todo.txt to done.txt and removes blank lines.
|
Moves done items from todo.txt to done.txt and removes blank lines.
|
||||||
|
|
||||||
|
command [ACTIONS]
|
||||||
|
Runs the remaining arguments using only todo.sh builtins.
|
||||||
|
Will not call any .todo.actions.d scripts.
|
||||||
|
|
||||||
del NUMBER [TERM]
|
del NUMBER [TERM]
|
||||||
rm NUMBER [TERM]
|
rm NUMBER [TERM]
|
||||||
Deletes the item on line NUMBER in todo.txt.
|
Deletes the item on line NUMBER in todo.txt.
|
||||||
@@ -119,6 +123,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 +137,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
|
||||||
@@ -197,9 +210,41 @@ archive()
|
|||||||
|
|
||||||
|
|
||||||
# == PROCESS OPTIONS ==
|
# == PROCESS OPTIONS ==
|
||||||
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
|
||||||
|
HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
||||||
|
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
|
||||||
|
HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
||||||
|
fi
|
||||||
|
;;
|
||||||
a )
|
a )
|
||||||
TODOTXT_AUTO_ARCHIVE=0
|
TODOTXT_AUTO_ARCHIVE=0
|
||||||
;;
|
;;
|
||||||
@@ -218,6 +263,22 @@ do
|
|||||||
p )
|
p )
|
||||||
TODOTXT_PLAIN=1
|
TODOTXT_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 )
|
||||||
TODOTXT_DATE_ON_ADD=1
|
TODOTXT_DATE_ON_ADD=1
|
||||||
;;
|
;;
|
||||||
@@ -285,6 +346,23 @@ shopt -s extglob
|
|||||||
# == HANDLE ACTION ==
|
# == HANDLE ACTION ==
|
||||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||||
|
|
||||||
|
## If the first argument is "command", run the rest of the arguments
|
||||||
|
## using todo.sh builtins.
|
||||||
|
## Else, run a actions script with the name of the command if it exists
|
||||||
|
## or fallback to using a builtin
|
||||||
|
if [ "$action" == command ]
|
||||||
|
then
|
||||||
|
## Get rid of "command" from arguments list
|
||||||
|
shift
|
||||||
|
## Reset action to new first argument
|
||||||
|
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
|
||||||
|
elif [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ]
|
||||||
|
then
|
||||||
|
"$HOME/.todo.actions.d/$action" "$@"
|
||||||
|
cleanup
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Only run if $action isn't found in .todo.actions.d
|
||||||
case $action in
|
case $action in
|
||||||
"add" | "a")
|
"add" | "a")
|
||||||
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
@@ -433,19 +511,51 @@ 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 -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/\(.*([D-Z]).*\)/'$PRI_X'\1 '$DEFAULT'/g;
|
||||||
|
}' \
|
||||||
|
| sed 's/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
| sed 's/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g' \
|
||||||
|
)"
|
||||||
echo "--"
|
echo "--"
|
||||||
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
|
||||||
command=`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'/' | grep -i $item `
|
command=$(
|
||||||
|
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/\(.*([D-Z]).*\)/'$PRI_X'\1 '$DEFAULT'/g;
|
||||||
|
}' \
|
||||||
|
| grep -i $item
|
||||||
|
)
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
for i in $*
|
for i 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 ;;
|
||||||
@@ -676,13 +786,6 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
* )
|
* )
|
||||||
if [ -d "$HOME/.todo.actions.d" ]; then
|
|
||||||
if [ -x "$HOME/.todo.actions.d/$action" ]; then
|
|
||||||
"$HOME/.todo.actions.d/$action" "$@"
|
|
||||||
else
|
|
||||||
usage
|
usage
|
||||||
fi
|
;;
|
||||||
else
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user