Merge branch 'harding/master'
This commit is contained in:
315
todo.sh
315
todo.sh
@@ -150,6 +150,8 @@ help()
|
|||||||
when it's added.
|
when it's added.
|
||||||
-v
|
-v
|
||||||
Verbose mode turns on confirmation messages
|
Verbose mode turns on confirmation messages
|
||||||
|
-vv
|
||||||
|
Extra verbose mode prints some debugging information
|
||||||
-V
|
-V
|
||||||
Displays version, license and credits
|
Displays version, license and credits
|
||||||
|
|
||||||
@@ -198,13 +200,13 @@ archive()
|
|||||||
{
|
{
|
||||||
#defragment blank lines
|
#defragment blank lines
|
||||||
sed -i.bak -e '/./!d' "$TODO_FILE"
|
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && grep "^x " "$TODO_FILE"
|
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||||
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||||
cp "$TODO_FILE" "$TMP_FILE"
|
cp "$TODO_FILE" "$TMP_FILE"
|
||||||
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
||||||
#[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Duplicate tasks have been removed."
|
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +228,7 @@ do
|
|||||||
unset HIDE_CONTEXTS_SUBSTITUTION
|
unset HIDE_CONTEXTS_SUBSTITUTION
|
||||||
else
|
else
|
||||||
## One or odd value -- hide context names
|
## One or odd value -- hide context names
|
||||||
HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
export HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'+' )
|
'+' )
|
||||||
@@ -242,7 +244,7 @@ do
|
|||||||
unset HIDE_PROJECTS_SUBSTITUTION
|
unset HIDE_PROJECTS_SUBSTITUTION
|
||||||
else
|
else
|
||||||
## One or odd value -- hide project names
|
## One or odd value -- hide project names
|
||||||
HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
export HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
a )
|
a )
|
||||||
@@ -276,14 +278,14 @@ do
|
|||||||
unset HIDE_PRIORITY_SUBSTITUTION
|
unset HIDE_PRIORITY_SUBSTITUTION
|
||||||
else
|
else
|
||||||
## One or odd value -- hide priority labels
|
## One or odd value -- hide priority labels
|
||||||
HIDE_PRIORITY_SUBSTITUTION="([A-Z])[[:space:]]"
|
export HIDE_PRIORITY_SUBSTITUTION="([A-Z])[[:space:]]"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
t )
|
t )
|
||||||
TODOTXT_DATE_ON_ADD=1
|
TODOTXT_DATE_ON_ADD=1
|
||||||
;;
|
;;
|
||||||
v )
|
v )
|
||||||
TODOTXT_VERBOSE=1
|
: $(( TODOTXT_VERBOSE++ ))
|
||||||
;;
|
;;
|
||||||
V )
|
V )
|
||||||
version
|
version
|
||||||
@@ -325,9 +327,9 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
|||||||
|
|
||||||
[ -z "$ACTION" ] && usage
|
[ -z "$ACTION" ] && usage
|
||||||
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
||||||
cd "$TODO_DIR" || die "Fatal Error: Unable to cd to $TODO_DIR"
|
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
|
||||||
|
|
||||||
echo '' > "$TMP_FILE" || die "Fatal Error: Unable to write in $TODO_DIR"
|
[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
|
||||||
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
||||||
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
||||||
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
||||||
@@ -343,6 +345,106 @@ fi
|
|||||||
# === HEAVY LIFTING ===
|
# === HEAVY LIFTING ===
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
|
|
||||||
|
_list() {
|
||||||
|
local FILE="$1"
|
||||||
|
## If the file starts with a "/" use absolute path. Otherwise,
|
||||||
|
## try to find it in either $TODO_DIR or using a relative path
|
||||||
|
if [ "${1:0:1}" == / ]
|
||||||
|
then
|
||||||
|
## Absolute path
|
||||||
|
src="$FILE"
|
||||||
|
elif [ -f "$TODO_DIR/$FILE" ]
|
||||||
|
then
|
||||||
|
## Path relative to todo.sh directory
|
||||||
|
src="$TODO_DIR/$1"
|
||||||
|
elif [ -f "$FILE" ]
|
||||||
|
then
|
||||||
|
## Path relative to current working directory
|
||||||
|
src="$FILE"
|
||||||
|
else
|
||||||
|
echo "TODO: File $FILE does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Get our search arguments, if any
|
||||||
|
shift ## was file name, new $1 is first search term
|
||||||
|
|
||||||
|
## Prefix the filter_command with the pre_filter_command
|
||||||
|
filter_command="${pre_filter_command:-}"
|
||||||
|
|
||||||
|
for search_term in "$@"
|
||||||
|
do
|
||||||
|
## See if the first character of $search_term is a dash
|
||||||
|
if [ ${search_term:0:1} != '-' ]
|
||||||
|
then
|
||||||
|
## First character isn't a dash: hide lines that don't match
|
||||||
|
## this $search_term
|
||||||
|
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||||
|
grep -i \"$search_term\" "
|
||||||
|
else
|
||||||
|
## First character is a dash: hide lines that match this
|
||||||
|
## $search_term
|
||||||
|
#
|
||||||
|
## Remove the first character (-) before adding to our filter command
|
||||||
|
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||||
|
grep -v -i \"${search_term:1}\" "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
## If post_filter_command is set, append it to the filter_command
|
||||||
|
[ -n "$post_filter_command" ] && {
|
||||||
|
filter_command="${filter_command:-}${filter_command:+ | }${post_filter_command:-}"
|
||||||
|
}
|
||||||
|
|
||||||
|
## Figure out how much padding we need to use
|
||||||
|
## We need one level of padding for each power of 10 $LINES uses
|
||||||
|
LINES=$( sed -n '$ =' "$src" )
|
||||||
|
PADDING=${#LINES}
|
||||||
|
|
||||||
|
## Number, sort, and mangle the file, then run the filter command,
|
||||||
|
## then mangle the file some more
|
||||||
|
command=$(
|
||||||
|
sed = "$src" \
|
||||||
|
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||||
|
| eval ${filter_command:-cat} \
|
||||||
|
| sed '''
|
||||||
|
s/^ /00000/;
|
||||||
|
s/^ /0000/;
|
||||||
|
s/^ /000/;
|
||||||
|
s/^ /00/;
|
||||||
|
s/^ /0/;
|
||||||
|
''' \
|
||||||
|
| sort -f -k2 \
|
||||||
|
| sed '''
|
||||||
|
/^[0-9]\{'$PADDING'\} 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
|
||||||
|
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||||
|
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||||
|
''' \
|
||||||
|
)
|
||||||
|
echo -ne "$command${command:+\n}"
|
||||||
|
|
||||||
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
|
NUMTASKS=$( echo -ne "$command" | sed -n '$ =' )
|
||||||
|
|
||||||
|
echo "--"
|
||||||
|
echo "TODO: ${NUMTASKS:-0} of $LINES tasks shown from $FILE"
|
||||||
|
fi
|
||||||
|
if [ $TODOTXT_VERBOSE -gt 1 ]
|
||||||
|
then
|
||||||
|
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
export -f _list
|
||||||
|
|
||||||
# == HANDLE ACTION ==
|
# == HANDLE ACTION ==
|
||||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||||
|
|
||||||
@@ -379,8 +481,8 @@ case $action in
|
|||||||
input="$now $input"
|
input="$now $input"
|
||||||
fi
|
fi
|
||||||
echo "$input" >> "$TODO_FILE"
|
echo "$input" >> "$TODO_FILE"
|
||||||
TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
"addto" )
|
"addto" )
|
||||||
@@ -393,8 +495,8 @@ case $action in
|
|||||||
|
|
||||||
if [ -f "$dest" ]; then
|
if [ -f "$dest" ]; then
|
||||||
echo "$input" >> "$dest"
|
echo "$input" >> "$dest"
|
||||||
TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
TASKNUM=$(sed -n '$ =' "$dest")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added to $dest on line $TASKNUM."
|
||||||
else
|
else
|
||||||
echo "TODO: Destination file $dest does not exist."
|
echo "TODO: Destination file $dest does not exist."
|
||||||
fi
|
fi
|
||||||
@@ -416,7 +518,7 @@ case $action in
|
|||||||
fi
|
fi
|
||||||
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
else
|
else
|
||||||
echo "TODO: Error appending task $item."
|
echo "TODO: Error appending task $item."
|
||||||
fi
|
fi
|
||||||
@@ -451,7 +553,7 @@ case $action in
|
|||||||
# leave blank line behind (preserves line numbers)
|
# leave blank line behind (preserves line numbers)
|
||||||
sed -i.bak -e $2"s/^.*//" "$TODO_FILE"
|
sed -i.bak -e $2"s/^.*//" "$TODO_FILE"
|
||||||
fi
|
fi
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$DELETEME' deleted."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
|
||||||
cleanup
|
cleanup
|
||||||
else
|
else
|
||||||
echo "TODO: No tasks were deleted."
|
echo "TODO: No tasks were deleted."
|
||||||
@@ -461,7 +563,7 @@ case $action in
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $3 removed from $item."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
"depri" | "dp" )
|
"depri" | "dp" )
|
||||||
@@ -478,8 +580,8 @@ case $action in
|
|||||||
#it's all good, continue
|
#it's all good, continue
|
||||||
sed -i.bak -e $2"s/^(.*) //" "$TODO_FILE"
|
sed -i.bak -e $2"s/^(.*) //" "$TODO_FILE"
|
||||||
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item deprioritized."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item deprioritized."
|
||||||
cleanup
|
cleanup
|
||||||
else
|
else
|
||||||
die "$errmsg"
|
die "$errmsg"
|
||||||
@@ -499,8 +601,8 @@ case $action in
|
|||||||
sed -i.bak $item"s/^(.*) //" "$TODO_FILE"
|
sed -i.bak $item"s/^(.*) //" "$TODO_FILE"
|
||||||
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item marked as done."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
|
||||||
|
|
||||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
archive
|
archive
|
||||||
@@ -509,108 +611,30 @@ case $action in
|
|||||||
|
|
||||||
|
|
||||||
"list" | "ls" )
|
"list" | "ls" )
|
||||||
item=$2
|
shift ## Was ls; new $1 is first search term
|
||||||
if [ -z "$item" ]; then
|
_list "$TODO_FILE" "$@"
|
||||||
echo -e "$( \
|
|
||||||
sed = "$TODO_FILE" \
|
cleanup
|
||||||
| 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 "--"
|
|
||||||
NUMTASKS=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
|
||||||
echo "TODO: $NUMTASKS tasks in $TODO_FILE."
|
|
||||||
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;
|
|
||||||
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
|
|
||||||
for i in $*
|
|
||||||
do
|
|
||||||
command=`echo "$command" | grep -i $i `
|
|
||||||
done
|
|
||||||
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"
|
|
||||||
fi
|
|
||||||
cleanup ;;
|
|
||||||
|
|
||||||
"listall" | "lsa" )
|
"listall" | "lsa" )
|
||||||
item=$2
|
shift ## Was lsa; new $1 is first search term
|
||||||
|
|
||||||
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||||
|
_list "$TMP_FILE" "$@"
|
||||||
|
|
||||||
if [ -z "$item" ]; then
|
cleanup
|
||||||
echo -e "`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`"
|
;;
|
||||||
else
|
|
||||||
command=`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item `
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
for i in $*
|
|
||||||
do
|
|
||||||
command=`echo "$command" | grep -i $i `
|
|
||||||
done
|
|
||||||
command=`echo "$command" | sort -f -k2`
|
|
||||||
echo -e "$command"
|
|
||||||
fi
|
|
||||||
cleanup ;;
|
|
||||||
|
|
||||||
|
|
||||||
"listfile" | "lf" )
|
"listfile" | "lf" )
|
||||||
src="$TODO_DIR/$2"
|
shift ## Was listfile, next $1 is file name
|
||||||
|
FILE="$1"
|
||||||
|
shift ## Was filename; next $1 is first search term
|
||||||
|
|
||||||
if [ -z "$3" ]; then
|
_list "$FILE" "$@"
|
||||||
item=""
|
|
||||||
else
|
cleanup
|
||||||
item=$3
|
;;
|
||||||
fi
|
|
||||||
if [ -f "$src" ]; then
|
|
||||||
if [ -z "$item" ]; then
|
|
||||||
echo -e "`sed = "$src" | 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'/'`"
|
|
||||||
if [ $TODOTXT_VERBOSE = 1 ]; then
|
|
||||||
echo "--"
|
|
||||||
NUMTASKS=$( sed '/./!d' "$src" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
|
||||||
echo "TODO: $NUMTASKS lines in $src."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
command=`sed = "$src" | 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 `
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
for i in $*
|
|
||||||
do
|
|
||||||
command=`echo "$command" | grep -i $i `
|
|
||||||
done
|
|
||||||
command=`echo "$command" | sort -f -k2`
|
|
||||||
echo -e "$command"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "TODO: File $src does not exist."
|
|
||||||
fi
|
|
||||||
cleanup ;;
|
|
||||||
|
|
||||||
"listcon" | "lsc" )
|
"listcon" | "lsc" )
|
||||||
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq
|
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq
|
||||||
@@ -622,28 +646,23 @@ case $action in
|
|||||||
|
|
||||||
|
|
||||||
"listpri" | "lsp" )
|
"listpri" | "lsp" )
|
||||||
pri=$( printf "%s\n" "$2" | tr 'a-z' 'A-Z' )
|
shift ## was "listpri", new $1 is priority to list
|
||||||
errmsg="usage: $0 listpri PRIORITY
|
|
||||||
note: PRIORITY must a single letter from A to Z."
|
|
||||||
|
|
||||||
if [ -z "$pri" ]; then
|
if [ "${1:-}" ]
|
||||||
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | 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 \([A-Z]\)
|
then
|
||||||
if [ $TODOTXT_VERBOSE = 1 ]; then
|
## A priority was specified
|
||||||
echo "--"
|
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
|
||||||
NUMTASKS=$(grep \([A-Z]\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
die "usage: $0 listpri PRIORITY
|
||||||
echo "TODO: $NUMTASKS prioritized tasks in $TODO_FILE."
|
note: PRIORITY must a single letter from A to Z."
|
||||||
fi
|
}
|
||||||
else
|
else
|
||||||
[[ "$pri" = +([A-Z]) ]] || die "$errmsg"
|
## No priority specified; show all priority tasks
|
||||||
|
pri="[[:upper:]]"
|
||||||
|
fi
|
||||||
|
pri="($pri)"
|
||||||
|
|
||||||
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | 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 \($pri\)
|
_list "$TODO_FILE" "$pri"
|
||||||
if [ $TODOTXT_VERBOSE = 1 ]; then
|
;;
|
||||||
echo "--"
|
|
||||||
NUMTASKS=$(grep \($pri\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
|
||||||
echo "TODO: $NUMTASKS tasks prioritized $pri in $TODO_FILE."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cleanup;;
|
|
||||||
|
|
||||||
"move" | "mv" )
|
"move" | "mv" )
|
||||||
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||||
@@ -678,7 +697,7 @@ note: PRIORITY must a single letter from A to Z."
|
|||||||
fi
|
fi
|
||||||
echo "$MOVEME" >> "$dest"
|
echo "$MOVEME" >> "$dest"
|
||||||
|
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
||||||
cleanup
|
cleanup
|
||||||
else
|
else
|
||||||
echo "TODO: No tasks moved."
|
echo "TODO: No tasks moved."
|
||||||
@@ -713,7 +732,7 @@ note: PRIORITY must a single letter from A to Z."
|
|||||||
|
|
||||||
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
else
|
else
|
||||||
echo "TODO: Error prepending task $item."
|
echo "TODO: Error prepending task $item."
|
||||||
fi
|
fi
|
||||||
@@ -736,8 +755,8 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
#it's all good, continue
|
#it's all good, continue
|
||||||
sed -i.bak -e $2"s/^(.*) //" -e $2"s/^/($newpri) /" "$TODO_FILE"
|
sed -i.bak -e $2"s/^(.*) //" -e $2"s/^/($newpri) /" "$TODO_FILE"
|
||||||
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item prioritized ($newpri)."
|
||||||
cleanup
|
cleanup
|
||||||
else
|
else
|
||||||
die "$errmsg"
|
die "$errmsg"
|
||||||
@@ -761,9 +780,9 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
|
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
[ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "replaced with"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $NEWTODO"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $NEWTODO"
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
"report" )
|
"report" )
|
||||||
@@ -771,17 +790,17 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
||||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||||
|
|
||||||
NUMLINES=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
|
NUMLINES=$( sed -n '$ =' "$TODO_FILE" )
|
||||||
if [ $NUMLINES = "0" ]; then
|
if [ ${NUMLINES:-0} = "0" ]; then
|
||||||
echo "datetime todos dones" >> "$REPORT_FILE"
|
echo "datetime todos dones" >> "$REPORT_FILE"
|
||||||
fi
|
fi
|
||||||
#now report
|
#now report
|
||||||
TOTAL=$(cat "$TODO_FILE" | wc -l | sed 's/^[ \t]*//')
|
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||||
TDONE=$(cat "$DONE_FILE" | wc -l | sed 's/^[ \t]*//')
|
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||||
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo $TOTAL; echo ' ';
|
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
|
||||||
echo $TDONE)
|
echo ${TDONE:-0})
|
||||||
echo $TECHO >> "$REPORT_FILE"
|
echo $TECHO >> "$REPORT_FILE"
|
||||||
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Report file updated."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||||
cat "$REPORT_FILE"
|
cat "$REPORT_FILE"
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user