-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #361 - add persistence for priority on completion, as an option defaulting to original behavior #362
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ TODO_SH=$(basename "$0") | |
TODO_FULL_SH="$0" | ||
export TODO_SH TODO_FULL_SH | ||
|
||
oneline_usage="$TODO_SH [-fhpantvV] [-d todo_config] action [task_number] [task_description]" | ||
oneline_usage="$TODO_SH [-fhpamntvV] [-d todo_config] action [task_number] [task_description]" | ||
|
||
usage() | ||
{ | ||
|
@@ -113,6 +113,8 @@ $indentedJoinedConfigFileLocations | |
Don't auto-archive tasks automatically on completion | ||
-A | ||
Auto-archive tasks automatically on completion | ||
-m | ||
Maintain priority field on completion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the "maintain" is meant to establish a mnemonic for the chosen option letter, but it sounds a bit confusing to my non-native ears. I'd prefer Don't remove a priority on completion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, on both points. |
||
-n | ||
Don't preserve line numbers; automatically remove blank lines | ||
on task deletion | ||
|
@@ -142,6 +144,7 @@ $indentedJoinedConfigFileLocations | |
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE | ||
TODOTXT_FORCE=1 is same as option -f | ||
TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1) | ||
TODOTXT_PRESERVE_PRIORITY=1 is same as option -m | ||
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 | ||
|
@@ -510,6 +513,7 @@ uppercasePriority() | |
#Preserving environment variables so they don't get clobbered by the config file | ||
OVR_TODOTXT_AUTO_ARCHIVE="$TODOTXT_AUTO_ARCHIVE" | ||
OVR_TODOTXT_FORCE="$TODOTXT_FORCE" | ||
OVR_TODOTXT_PRESERVE_PRIORITY="$TODOTXT_PRESERVE_PRIORITY" | ||
OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS" | ||
OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN" | ||
OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD" | ||
|
@@ -524,7 +528,7 @@ OVR_TODOTXT_FINAL_FILTER="$TODOTXT_FINAL_FILTER" | |
export GREP_OPTIONS="" | ||
|
||
# == PROCESS OPTIONS == | ||
while getopts ":fhpcnNaAtTvVx+@Pd:" Option | ||
while getopts ":fhpcmnNaAtTvVx+@Pd:" Option | ||
do | ||
case $Option in | ||
'@') | ||
|
@@ -581,7 +585,10 @@ do | |
set -- '-h' 'shorthelp' | ||
OPTIND=2 | ||
;; | ||
n) | ||
m ) | ||
OVR_TODOTXT_PRESERVE_PRIORITY=1 | ||
;; | ||
n ) | ||
OVR_TODOTXT_PRESERVE_LINE_NUMBERS=0 | ||
;; | ||
N) | ||
|
@@ -632,6 +639,7 @@ shift $((OPTIND - 1)) | |
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1} | ||
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0} | ||
TODOTXT_FORCE=${TODOTXT_FORCE:-0} | ||
TODOTXT_PRESERVE_PRIORITY=${TODOTXT_PRESERVE_PRIORITY:-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} | ||
|
@@ -738,6 +746,9 @@ fi | |
if [ -n "$OVR_TODOTXT_FORCE" ] ; then | ||
TODOTXT_FORCE="$OVR_TODOTXT_FORCE" | ||
fi | ||
if [ -n "$OVR_TODOTXT_PRESERVE_PRIORITY" ] ; then | ||
TODOTXT_PRESERVE_PRIORITY="$OVR_TODOTXT_PRESERVE_PRIORITY" | ||
fi | ||
if [ -n "$OVR_TODOTXT_PRESERVE_LINE_NUMBERS" ] ; then | ||
TODOTXT_PRESERVE_LINE_NUMBERS="$OVR_TODOTXT_PRESERVE_LINE_NUMBERS" | ||
fi | ||
|
@@ -1231,7 +1242,7 @@ 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" | ||
[[ "$TODOTXT_PRESERVE_PRIORITY" = "1" ]] || sed -i.bak $item"s/^(.) //" "$TODO_FILE" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those purely cosmetic, I'd prefer to keep the variable |
||
sed -i.bak "${item}s|^|x $now |" "$TODO_FILE" | ||
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then | ||
getNewtodo "$item" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this needs to be exposed as a command-line option - it struck me as noteworthy that most of your proposed change is about these boilerplate modifications, and the actual extension is just a few lines.
I guess most users would like to permanently configure
TODOTXT_PRESERVE_PRIORITY=1
in the config file, anyway. (The same argument applies to the existing auto-archive, preserve line-numbers, and date prepending; unfortunately, these already have set the precedent in favor of short options, and it's getting increasingly more difficult to find good candidate letters.)For my own scripts, I'd just offer a long GNU-style command-line option a la
--keep-priority-on-done
for this. But this would mean switching to GNUgetopt
(which is a separate dependency on Mac OS), and many adaptations. (And I wouldn't expect you to do this as part of this PR - this is just me brainstorming for the co-developer.)