Compare commits
7 Commits
v2.11.0
...
19dde076cf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19dde076cf | ||
|
|
3bc3616651 | ||
|
|
d589fd0570 | ||
|
|
7a30199fe0 | ||
|
|
867ade5701 | ||
|
|
14f5de1579 | ||
|
|
7ec2a1263e |
33
tests/t1040-add-priority.sh
Executable file
33
tests/t1040-add-priority.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
test_description='test the priority on add feature'
|
||||
. ./test-lib.sh
|
||||
|
||||
## Normal use case
|
||||
echo "export TODOTXT_PRIORITY_ON_ADD=A" >> todo.cfg
|
||||
|
||||
test_todo_session 'config file priority' <<EOF
|
||||
>>> todo.sh add take out the trash
|
||||
1 (A) take out the trash
|
||||
TODO: 1 added.
|
||||
|
||||
>>> todo.sh -p list
|
||||
1 (A) take out the trash
|
||||
--
|
||||
TODO: 1 of 1 tasks shown
|
||||
EOF
|
||||
|
||||
## Wrong value in config var
|
||||
echo "export TODOTXT_PRIORITY_ON_ADD=1" >> todo.cfg
|
||||
|
||||
test_todo_session 'config file wrong priority' <<EOF
|
||||
>>> todo.sh add fail to take out the trash
|
||||
=== 1
|
||||
TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now "1").
|
||||
|
||||
>>> todo.sh -p list
|
||||
=== 1
|
||||
TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now "1").
|
||||
EOF
|
||||
|
||||
test_done
|
||||
4
todo.cfg
4
todo.cfg
@@ -67,6 +67,10 @@ export REPORT_FILE="$TODO_DIR/report.txt"
|
||||
# export COLOR_PROJECT=$RED
|
||||
# export COLOR_CONTEXT=$RED
|
||||
|
||||
# ... and for date extensions (due:yyyy-mm-dd, t:yyyy-mm-dd and again:X)
|
||||
#
|
||||
# export COLOR_DATEEXT=$LIGHT_BLUE
|
||||
|
||||
# === BEHAVIOR ===
|
||||
|
||||
## customize list output
|
||||
|
||||
173
todo.sh
173
todo.sh
@@ -1,4 +1,4 @@
|
||||
#! /bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# === HEAVY LIFTING ===
|
||||
shopt -s extglob extquote
|
||||
@@ -51,7 +51,7 @@ shorthelp()
|
||||
deduplicate
|
||||
del|rm ITEM# [TERM]
|
||||
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
||||
do ITEM#[, ITEM#, ITEM#, ...]
|
||||
done|do ITEM#[, ITEM#, ITEM#, ...]
|
||||
help [ACTION...]
|
||||
list|ls [TERM...]
|
||||
listall|lsa [TERM...]
|
||||
@@ -134,7 +134,7 @@ help()
|
||||
|
||||
EndOptionsHelp
|
||||
|
||||
[ $TODOTXT_VERBOSE -gt 1 ] && cat <<-'EndVerboseHelp'
|
||||
[ "$TODOTXT_VERBOSE" -gt 1 ] && cat <<-'EndVerboseHelp'
|
||||
Environment variables:
|
||||
TODOTXT_AUTO_ARCHIVE is same as option -a (0)/-A (1)
|
||||
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE
|
||||
@@ -142,6 +142,7 @@ help()
|
||||
TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1)
|
||||
TODOTXT_PLAIN is same as option -p (1)/-c (0)
|
||||
TODOTXT_DATE_ON_ADD is same as option -t (1)/-T (0)
|
||||
TODOTXT_PRIORITY_ON_ADD=pri default priority A-Z
|
||||
TODOTXT_VERBOSE=1 is same as option -v
|
||||
TODOTXT_DISABLE_FILTER=1 is same as option -x
|
||||
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
|
||||
@@ -200,6 +201,7 @@ actionsHelp()
|
||||
Deprioritizes (removes the priority) from the task(s)
|
||||
on line ITEM# in todo.txt.
|
||||
|
||||
done ITEM#[, ITEM#, ITEM#, ...]
|
||||
do ITEM#[, ITEM#, ITEM#, ...]
|
||||
Marks task(s) on line ITEM# as done in todo.txt.
|
||||
|
||||
@@ -292,7 +294,7 @@ addonHelp()
|
||||
didPrintAddonActionsHeader=
|
||||
for action in "$TODO_ACTIONS_DIR"/*
|
||||
do
|
||||
if [ -f "$action" -a -x "$action" ]; then
|
||||
if [ -f "$action" ] && [ -x "$action" ]; then
|
||||
if [ ! "$didPrintAddonActionsHeader" ]; then
|
||||
cat <<-EndAddonActionsHeader
|
||||
Add-on Actions:
|
||||
@@ -300,14 +302,14 @@ addonHelp()
|
||||
didPrintAddonActionsHeader=1
|
||||
fi
|
||||
"$action" usage
|
||||
elif [ -d "$action" -a -x "$action/$(basename $action)" ]; then
|
||||
elif [ -d "$action" ] && [ -x "$action"/"$(basename "$action")" ]; then
|
||||
if [ ! "$didPrintAddonActionsHeader" ]; then
|
||||
cat <<-EndAddonActionsHeader
|
||||
Add-on Actions:
|
||||
EndAddonActionsHeader
|
||||
didPrintAddonActionsHeader=1
|
||||
fi
|
||||
"$action/$(basename $action)" usage
|
||||
"$action"/"$(basename "$action")" usage
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -318,10 +320,10 @@ actionUsage()
|
||||
for actionName
|
||||
do
|
||||
action="${TODO_ACTIONS_DIR}/${actionName}"
|
||||
if [ -f "$action" -a -x "$action" ]; then
|
||||
if [ -f "$action" ] && [ -x "$action" ]; then
|
||||
"$action" usage
|
||||
elif [ -d "$action" -a -x "$action/$(basename $action)" ]; then
|
||||
"$action/$(basename $action)" usage
|
||||
elif [ -d "$action" ] && [ -x "$action"/"$(basename "$action")" ]; then
|
||||
"$action"/"$(basename "$action")" usage
|
||||
else
|
||||
builtinActionUsage=$(actionsHelp | sed -n -e "/^ ${actionName//\//\\/} /,/^\$/p" -e "/^ ${actionName//\//\\/}$/,/^\$/p")
|
||||
if [ "$builtinActionUsage" ]; then
|
||||
@@ -376,8 +378,9 @@ getPrefix()
|
||||
# Parameters: $1: todo file; empty means $TODO_FILE.
|
||||
# Returns: Uppercase FILE prefix to be used in place of "TODO:" where
|
||||
# a different todo file can be specified.
|
||||
local base=$(basename "${1:-$TODO_FILE}")
|
||||
echo "${base%%.[^.]*}" | tr 'a-z' 'A-Z'
|
||||
local base
|
||||
base=$(basename "${1:-$TODO_FILE}")
|
||||
echo "${base%%.[^.]*}" | tr '[:lower:]' '[:upper:]'
|
||||
}
|
||||
|
||||
getTodo()
|
||||
@@ -402,8 +405,8 @@ getNewtodo()
|
||||
# Postcondition: $newtodo contains task text.
|
||||
|
||||
local item=$1
|
||||
[ -z "$item" ] && die 'Programming error: $item should exist.'
|
||||
[ "${item//[0-9]/}" ] && die 'Programming error: $item should be numeric.'
|
||||
[ -z "$item" ] && die "Programming error: $item should exist."
|
||||
[ "${item//[0-9]/}" ] && die "Programming error: $item should be numeric."
|
||||
|
||||
newtodo=$(sed "$item!d" "${2:-$TODO_FILE}")
|
||||
[ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item."
|
||||
@@ -427,7 +430,7 @@ replaceOrPrepend()
|
||||
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "$querytext"
|
||||
read -e -r input
|
||||
read -r -i "$todo" -e input
|
||||
else
|
||||
input=$*
|
||||
fi
|
||||
@@ -437,7 +440,7 @@ replaceOrPrepend()
|
||||
priority=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\1/" "$TODO_FILE")
|
||||
prepdate=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\2/" "$TODO_FILE")
|
||||
|
||||
if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e "s/${priAndDateExpr}.*/\\1\\2/")" ]; then
|
||||
if [ "$prepdate" ] && [ "$action" = "replace" ] && [ "$(echo "$input"|sed -e "s/${priAndDateExpr}.*/\\1\\2/")" ]; then
|
||||
# If the replaced text starts with a [priority +] date, it will replace
|
||||
# the existing date, too.
|
||||
prepdate=
|
||||
@@ -448,7 +451,7 @@ replaceOrPrepend()
|
||||
# date again.
|
||||
cleaninput "for sed"
|
||||
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
getNewtodo "$item"
|
||||
case "$action" in
|
||||
replace)
|
||||
@@ -473,7 +476,7 @@ uppercasePriority()
|
||||
do
|
||||
upperPriority="${upperPriority};s/^[(]${lower[i]}[)]/(${upper[i]})/"
|
||||
done
|
||||
input=$(echo "$input" | sed $upperPriority)
|
||||
input=$(echo "$input" | sed "$upperPriority")
|
||||
}
|
||||
|
||||
#Preserving environment variables so they don't get clobbered by the config file
|
||||
@@ -482,6 +485,7 @@ OVR_TODOTXT_FORCE="$TODOTXT_FORCE"
|
||||
OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS"
|
||||
OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN"
|
||||
OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD"
|
||||
OVR_TODOTXT_PRIORITY_ON_ADD="$TODOTXT_PRIORITY_ON_ADD"
|
||||
OVR_TODOTXT_DISABLE_FILTER="$TODOTXT_DISABLE_FILTER"
|
||||
OVR_TODOTXT_VERBOSE="$TODOTXT_VERBOSE"
|
||||
OVR_TODOTXT_DEFAULT_ACTION="$TODOTXT_DEFAULT_ACTION"
|
||||
@@ -489,7 +493,7 @@ OVR_TODOTXT_SORT_COMMAND="$TODOTXT_SORT_COMMAND"
|
||||
OVR_TODOTXT_FINAL_FILTER="$TODOTXT_FINAL_FILTER"
|
||||
|
||||
# Prevent GREP_OPTIONS from malforming grep's output
|
||||
GREP_OPTIONS=""
|
||||
export GREP_OPTIONS=""
|
||||
|
||||
# == PROCESS OPTIONS ==
|
||||
while getopts ":fhpcnNaAtTvVx+@Pd:" Option
|
||||
@@ -502,7 +506,7 @@ do
|
||||
## number shows context names and an odd number hides context
|
||||
## names.
|
||||
: $(( HIDE_CONTEXT_NAMES++ ))
|
||||
if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
||||
if [ $(( HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
||||
then
|
||||
## Zero or even value -- show context names
|
||||
unset HIDE_CONTEXTS_SUBSTITUTION
|
||||
@@ -518,7 +522,7 @@ do
|
||||
## number shows project names and an odd number hides project
|
||||
## names.
|
||||
: $(( HIDE_PROJECT_NAMES++ ))
|
||||
if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
||||
if [ $(( HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
||||
then
|
||||
## Zero or even value -- show project names
|
||||
unset HIDE_PROJECTS_SUBSTITUTION
|
||||
@@ -565,7 +569,7 @@ do
|
||||
## number shows priority labels and an odd number hides priority
|
||||
## labels.
|
||||
: $(( HIDE_PRIORITY_LABELS++ ))
|
||||
if [ $(( $HIDE_PRIORITY_LABELS % 2 )) -eq 0 ]
|
||||
if [ $(( HIDE_PRIORITY_LABELS % 2 )) -eq 0 ]
|
||||
then
|
||||
## Zero or even value -- show priority labels
|
||||
unset HIDE_PRIORITY_SUBSTITUTION
|
||||
@@ -589,9 +593,12 @@ do
|
||||
x)
|
||||
OVR_TODOTXT_DISABLE_FILTER=1
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
# defaults if not yet defined
|
||||
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
|
||||
@@ -601,6 +608,7 @@ TODOTXT_FORCE=${TODOTXT_FORCE:-0}
|
||||
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
||||
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
|
||||
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
|
||||
TODOTXT_PRIORITY_ON_ADD=${TODOTXT_PRIORITY_ON_ADD:-}
|
||||
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
|
||||
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
|
||||
TODOTXT_DISABLE_FILTER=${TODOTXT_DISABLE_FILTER:-}
|
||||
@@ -608,7 +616,7 @@ TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat}
|
||||
TODOTXT_GLOBAL_CFG_FILE=${TODOTXT_GLOBAL_CFG_FILE:-/etc/todo/config}
|
||||
|
||||
# Export all TODOTXT_* variables
|
||||
export ${!TODOTXT_@}
|
||||
export "${!TODOTXT_@}"
|
||||
|
||||
# Default color map
|
||||
export NONE=''
|
||||
@@ -636,9 +644,10 @@ export PRI_B=$GREEN # color for B priority
|
||||
export PRI_C=$LIGHT_BLUE # color for C priority
|
||||
export PRI_X=$WHITE # color unless explicitly defined
|
||||
|
||||
# Default project and context colors.
|
||||
# Default project, context and dateext colors.
|
||||
export COLOR_PROJECT=$NONE
|
||||
export COLOR_CONTEXT=$NONE
|
||||
export COLOR_DATEEXT=$NONE
|
||||
|
||||
# Default highlight colors.
|
||||
export COLOR_DONE=$LIGHT_GREY # color for done (but not yet archived) tasks
|
||||
@@ -695,7 +704,7 @@ export SENTENCE_DELIMITERS=',.:;'
|
||||
}
|
||||
|
||||
|
||||
if [ -z "$TODO_ACTIONS_DIR" -o ! -d "$TODO_ACTIONS_DIR" ]
|
||||
if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ]
|
||||
then
|
||||
TODO_ACTIONS_DIR="$HOME/.todo/actions"
|
||||
export TODO_ACTIONS_DIR
|
||||
@@ -740,6 +749,9 @@ fi
|
||||
if [ -n "$OVR_TODOTXT_DATE_ON_ADD" ] ; then
|
||||
TODOTXT_DATE_ON_ADD="$OVR_TODOTXT_DATE_ON_ADD"
|
||||
fi
|
||||
if [ -n "$OVR_TODOTXT_PRIORITY_ON_ADD" ] ; then
|
||||
TODOTXT_PRIORITY_ON_ADD="$OVR_TODOTXT_PRIORITY_ON_ADD"
|
||||
fi
|
||||
if [ -n "$OVR_TODOTXT_DISABLE_FILTER" ] ; then
|
||||
TODOTXT_DISABLE_FILTER="$OVR_TODOTXT_DISABLE_FILTER"
|
||||
fi
|
||||
@@ -759,16 +771,19 @@ fi
|
||||
ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
||||
|
||||
[ -z "$ACTION" ] && usage
|
||||
[ -d "$TODO_DIR" ] || mkdir -p $TODO_DIR 2> /dev/null || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
|
||||
[ -d "$TODO_DIR" ] || mkdir -p "$TODO_DIR" 2> /dev/null || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
|
||||
( cd "$TODO_DIR" ) || dieWithHelp "$1" "Fatal Error: Unable to cd to $TODO_DIR"
|
||||
[ -z "$TODOTXT_PRIORITY_ON_ADD" ] \
|
||||
|| echo "$TODOTXT_PRIORITY_ON_ADD" | grep -q "^[A-Z]$" \
|
||||
|| die "TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now \"$TODOTXT_PRIORITY_ON_ADD\")."
|
||||
|
||||
[ -f "$TODO_FILE" -o -c "$TODO_FILE" ] || > "$TODO_FILE"
|
||||
[ -f "$DONE_FILE" -o -c "$DONE_FILE" ] || > "$DONE_FILE"
|
||||
[ -f "$REPORT_FILE" -o -c "$REPORT_FILE" ] || > "$REPORT_FILE"
|
||||
[ -f "$TODO_FILE" ] || [ -c "$TODO_FILE" ] || > "$TODO_FILE"
|
||||
[ -f "$DONE_FILE" ] || [ -c "$DONE_FILE" ] || > "$DONE_FILE"
|
||||
[ -f "$REPORT_FILE" ] || [ -c "$REPORT_FILE" ] || > "$REPORT_FILE"
|
||||
|
||||
if [ $TODOTXT_PLAIN = 1 ]; then
|
||||
for clr in ${!PRI_@}; do
|
||||
export $clr=$NONE
|
||||
export "$clr"=$NONE
|
||||
done
|
||||
PRI_X=$NONE
|
||||
DEFAULT=$NONE
|
||||
@@ -786,12 +801,17 @@ _addto() {
|
||||
cleaninput
|
||||
uppercasePriority
|
||||
|
||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||
if [[ "$TODOTXT_DATE_ON_ADD" -eq 1 ]]; then
|
||||
now=$(date '+%Y-%m-%d')
|
||||
input=$(echo "$input" | sed -e 's/^\(([A-Z]) \)\{0,1\}/\1'"$now /")
|
||||
fi
|
||||
if [[ -n "$TODOTXT_PRIORITY_ON_ADD" ]]; then
|
||||
if ! echo "$input" | grep -q '^([A-Z])'; then
|
||||
input=$(echo -n "($TODOTXT_PRIORITY_ON_ADD) " ; echo "$input")
|
||||
fi
|
||||
fi
|
||||
echo "$input" >> "$file"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
TASKNUM=$(sed -n '$ =' "$file")
|
||||
echo "$TASKNUM $input"
|
||||
echo "$(getPrefix "$file"): $TASKNUM added."
|
||||
@@ -859,7 +879,7 @@ _list() {
|
||||
|
||||
_format "$src" '' "$@"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
echo "--"
|
||||
echo "$(getPrefix "$src"): ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||
fi
|
||||
@@ -919,7 +939,7 @@ _format()
|
||||
s/^ /00/;
|
||||
s/^ /0/;
|
||||
''' \
|
||||
| eval ${TODOTXT_SORT_COMMAND} \
|
||||
| eval "${TODOTXT_SORT_COMMAND}" \
|
||||
| awk '''
|
||||
function highlight(colorVar, color) {
|
||||
color = ENVIRON[colorVar]
|
||||
@@ -945,6 +965,9 @@ _format()
|
||||
ctx_beg = highlight("COLOR_CONTEXT")
|
||||
ctx_end = (ctx_beg ? (highlight("DEFAULT") clr) : "")
|
||||
|
||||
dtx_beg = highlight("COLOR_DATEEXT")
|
||||
dtx_end = (dtx_beg ? (highlight("DEFAULT") clr) : "")
|
||||
|
||||
gsub(/[ \t][ \t]*/, "\n&\n")
|
||||
len = split($0, words, /\n/)
|
||||
|
||||
@@ -954,6 +977,8 @@ _format()
|
||||
printf "%s", prj_beg words[i] prj_end
|
||||
} else if (words[i] ~ /^[@].*[A-Za-z0-9_]$/) {
|
||||
printf "%s", ctx_beg words[i] ctx_end
|
||||
} else if (words[i] ~ /^(due|t|again):/) {
|
||||
printf "%s", dtx_beg words[i] dtx_end
|
||||
} else {
|
||||
printf "%s", words[i]
|
||||
}
|
||||
@@ -970,11 +995,11 @@ _format()
|
||||
)
|
||||
[ "$filtered_items" ] && echo "$filtered_items"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
||||
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 1 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 1 ]; then
|
||||
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
||||
fi
|
||||
}
|
||||
@@ -992,7 +1017,7 @@ listWordsWithSigil()
|
||||
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format die
|
||||
|
||||
# == HANDLE ACTION ==
|
||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||
action=$( printf "%s\n" "$ACTION" | tr '[:upper:]' '[:lower:]' )
|
||||
|
||||
## If the first argument is "command", run the rest of the arguments
|
||||
## using todo.sh builtins.
|
||||
@@ -1003,12 +1028,12 @@ 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 "$TODO_ACTIONS_DIR/$action" -a -x "$TODO_ACTIONS_DIR/$action/$action" ]
|
||||
action=$( printf "%s\n" "$1" | tr '[:upper:]' '[:lower:]' )
|
||||
elif [ -d "$TODO_ACTIONS_DIR/$action" ] && [ -x "$TODO_ACTIONS_DIR/$action/$action" ]
|
||||
then
|
||||
"$TODO_ACTIONS_DIR/$action/$action" "$@"
|
||||
exit $?
|
||||
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
|
||||
elif [ -d "$TODO_ACTIONS_DIR" ] && [ -x "$TODO_ACTIONS_DIR/$action" ]
|
||||
then
|
||||
"$TODO_ACTIONS_DIR/$action" "$@"
|
||||
exit $?
|
||||
@@ -1082,8 +1107,8 @@ case $action in
|
||||
esac
|
||||
cleaninput "for sed"
|
||||
|
||||
if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if sed -i.bak "${item} s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
fi
|
||||
@@ -1095,10 +1120,10 @@ case $action in
|
||||
"archive" )
|
||||
# defragment blank lines
|
||||
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||
[ "$TODOTXT_VERBOSE" -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
echo "TODO: $TODO_FILE archived."
|
||||
fi
|
||||
;;
|
||||
@@ -1119,12 +1144,12 @@ case $action in
|
||||
if [ "$ANSWER" = "y" ]; then
|
||||
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||
# delete line (changes line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$TODO_FILE"
|
||||
sed -i.bak -e "${item}s/^.*//" -e '/./!d' "$TODO_FILE"
|
||||
else
|
||||
# leave blank line behind (preserves line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
|
||||
sed -i.bak -e "${item}s/^.*//" "$TODO_FILE"
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
echo "$item $todo"
|
||||
echo "TODO: $item deleted."
|
||||
fi
|
||||
@@ -1133,18 +1158,18 @@ case $action in
|
||||
fi
|
||||
else
|
||||
sed -i.bak \
|
||||
-e $item"s/^\((.) \)\{0,1\} *$3 */\1/g" \
|
||||
-e $item"s/ *$3 *\$//g" \
|
||||
-e $item"s/ *$3 */ /g" \
|
||||
-e $item"s/ *$3 */ /g" \
|
||||
-e $item"s/$3//g" \
|
||||
-e "${item}s/^\((.) \)\{0,1\} *$3 */\1/g" \
|
||||
-e "${item}s/ *$3 *\$//g" \
|
||||
-e "${item}s/ *$3 */ /g" \
|
||||
-e "${item}s/ *$3 */ /g" \
|
||||
-e "${item}s/$3//g" \
|
||||
"$TODO_FILE"
|
||||
getNewtodo "$item"
|
||||
if [ "$todo" = "$newtodo" ]; then
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item $todo"
|
||||
[ "$TODOTXT_VERBOSE" -gt 0 ] && echo "$item $todo"
|
||||
die "TODO: '$3' not found; no removal done."
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
echo "$item $todo"
|
||||
echo "TODO: Removed '$3' from task."
|
||||
echo "$item $newtodo"
|
||||
@@ -1163,8 +1188,8 @@ case $action in
|
||||
getTodo "$item"
|
||||
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
sed -i.bak -e "${item}s/^(.) //" "$TODO_FILE"
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
echo "TODO: $item deprioritized."
|
||||
@@ -1175,7 +1200,7 @@ case $action in
|
||||
done
|
||||
;;
|
||||
|
||||
"do" )
|
||||
"do" | "done" )
|
||||
errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]"
|
||||
# shift so we get arguments to the do request
|
||||
shift;
|
||||
@@ -1190,9 +1215,9 @@ case $action in
|
||||
if [ "${todo:0:2}" != "x " ]; then
|
||||
now=$(date '+%Y-%m-%d')
|
||||
# remove priority once item is done
|
||||
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||
sed -i.bak $item"s|^|x $now |" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
sed -i.bak "${item}s/^(.) //" "$TODO_FILE"
|
||||
sed -i.bak "${item}s|^|x $now |" "$TODO_FILE"
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
echo "TODO: $item marked as done."
|
||||
@@ -1249,7 +1274,7 @@ case $action in
|
||||
post_filter_command="${post_filter_command:-}${post_filter_command:+ | }awk -v TOTAL=$TOTAL -v PADDING=$PADDING '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
|
||||
cat "$TODO_FILE" "$DONE_FILE" | TODOTXT_VERBOSE=0 _format '' "$PADDING" "$@"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$TODO_FILE" 1 "$@" | sed -n '$ =')
|
||||
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$DONE_FILE" 1 "$@" | sed -n '$ =')
|
||||
@@ -1263,8 +1288,8 @@ case $action in
|
||||
"listfile" | "lf" )
|
||||
shift ## Was listfile, next $1 is file name
|
||||
if [ $# -eq 0 ]; then
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "Files in the todo.txt directory:"
|
||||
cd "$TODO_DIR" && ls -1 *.txt
|
||||
[ "$TODOTXT_VERBOSE" -gt 0 ] && echo "Files in the todo.txt directory:"
|
||||
cd "$TODO_DIR" && ls -1 -- *.txt
|
||||
else
|
||||
FILE="$1"
|
||||
shift ## Was filename; next $1 is first search term
|
||||
@@ -1286,7 +1311,7 @@ case $action in
|
||||
"listpri" | "lsp" )
|
||||
shift ## was "listpri", new $1 is priority to list or first TERM
|
||||
|
||||
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep -e '^[A-Z]$' -e '^[A-Z]-[A-Z]$') && shift || pri="A-Z"
|
||||
pri=$(printf "%s\n" "$1" | tr '[:lower:]' '[:upper:]' | grep -e '^[A-Z]$' -e '^[A-Z]-[A-Z]$') && shift || pri="A-Z"
|
||||
post_filter_command="${post_filter_command:-}${post_filter_command:+ | }grep '^ *[0-9]\+ ([${pri}]) '"
|
||||
_list "$TODO_FILE" "$@"
|
||||
;;
|
||||
@@ -1315,14 +1340,14 @@ case $action in
|
||||
if [ "$ANSWER" = "y" ]; then
|
||||
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||
# delete line (changes line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
|
||||
sed -i.bak -e "${item}s/^.*//" -e '/./!d' "$src"
|
||||
else
|
||||
# leave blank line behind (preserves line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" "$src"
|
||||
sed -i.bak -e "${item}s/^.*//" "$src"
|
||||
fi
|
||||
echo "$todo" >> "$dest"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
echo "$item $todo"
|
||||
echo "TODO: $item moved from '$src' to '$dest'."
|
||||
fi
|
||||
@@ -1338,7 +1363,7 @@ case $action in
|
||||
|
||||
"pri" | "p" )
|
||||
item=$2
|
||||
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
|
||||
newpri=$( printf "%s\n" "$3" | tr '[:lower:]' '[:upper:]' )
|
||||
|
||||
errmsg="usage: $TODO_SH pri ITEM# PRIORITY
|
||||
note: PRIORITY must be anywhere from A to Z."
|
||||
@@ -1353,9 +1378,9 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
fi
|
||||
|
||||
if [ "$oldpri" != "$newpri" ]; then
|
||||
sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE"
|
||||
sed -i.bak -e "${item}s/^(.) //" -e "${item}s/^/($newpri) /" "$TODO_FILE"
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
if [ "$oldpri" != "$newpri" ]; then
|
||||
@@ -1389,12 +1414,12 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
LASTDATA=${LASTREPORT#* } # Strip timestamp.
|
||||
if [ "$LASTDATA" = "$NEWDATA" ]; then
|
||||
echo "$LASTREPORT"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file is up-to-date."
|
||||
[ "$TODOTXT_VERBOSE" -gt 0 ] && echo "TODO: Report file is up-to-date."
|
||||
else
|
||||
NEWREPORT="$(date +%Y-%m-%dT%T) ${NEWDATA}"
|
||||
echo "${NEWREPORT}" >> "$REPORT_FILE"
|
||||
echo "${NEWREPORT}"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||
[ "$TODOTXT_VERBOSE" -gt 0 ] && echo "TODO: Report file updated."
|
||||
fi
|
||||
;;
|
||||
|
||||
@@ -1447,9 +1472,9 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
cd "$TODO_ACTIONS_DIR" || exit $?
|
||||
for action in *
|
||||
do
|
||||
if [ -f "$action" -a -x "$action" ]; then
|
||||
if [ -f "$action" ] && [ -x "$action" ]; then
|
||||
echo "$action"
|
||||
elif [ -d "$action" -a -x "$action/$action" ]; then
|
||||
elif [ -d "$action" ] && [ -x "$action/$action" ]; then
|
||||
echo "$action"
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user