Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a6ff81e28 | ||
|
|
0b3d9109de | ||
|
|
ad40ef0f18 | ||
|
|
31216fe365 | ||
|
|
7f5c8fb3e1 | ||
|
|
3e7b60abcd | ||
|
|
cc3e5f73aa | ||
|
|
52604ebf78 | ||
|
|
bbe153b9bb | ||
|
|
ec54a032cb | ||
|
|
758cdc5551 | ||
|
|
02dc030225 | ||
|
|
7b769b2eea | ||
|
|
39ee9ab045 | ||
|
|
1e5902d0e2 | ||
|
|
3df7497287 | ||
|
|
07bb979d43 | ||
|
|
7e04849a4f | ||
|
|
f8b2646b92 | ||
|
|
02980ae7ee | ||
|
|
12bbf8fe67 | ||
|
|
ab78607506 | ||
|
|
6be78ca5fa | ||
|
|
9ab77253db | ||
|
|
cf3c5312bf | ||
|
|
37a7bb0e8a | ||
|
|
ed8e8e24d9 | ||
|
|
d6f00ca42f | ||
|
|
a03a3bf66b | ||
|
|
448cecb91d | ||
|
|
ee59233c36 | ||
|
|
f55f5e8b5f | ||
|
|
d508ed9dee | ||
|
|
62f3313ff9 | ||
|
|
6bc374c5f2 | ||
|
|
87959a8aa8 | ||
|
|
3e9d40ebd7 | ||
|
|
6bc05000d9 | ||
|
|
717f052f13 | ||
|
|
4ee8c332ed | ||
|
|
88caf44e9e | ||
|
|
db66767170 | ||
|
|
f8f8e83c40 | ||
|
|
2648bb047c | ||
|
|
bbff2d13bb | ||
|
|
e4c7979888 | ||
|
|
47c7ba75b3 | ||
|
|
2bd2e9f7bd | ||
|
|
f37cedc7ca | ||
|
|
7b2c9f080a | ||
|
|
98646a575a | ||
|
|
e6649e6293 | ||
|
|
eb61752708 | ||
|
|
5683490c0e | ||
|
|
20e6892775 | ||
|
|
fd9b002ce1 | ||
|
|
7736e6b4fa | ||
|
|
586abe8282 | ||
|
|
25c6505007 | ||
|
|
9c6efe2ed7 | ||
|
|
7ecda8973b |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
VERSION-FILE
|
||||
38
GEN-VERSION-FILE
Executable file
38
GEN-VERSION-FILE
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Based on git's GIT-VERSION-GEN.
|
||||
|
||||
VF=VERSION-FILE
|
||||
DEF_VER=v2.2
|
||||
|
||||
LF='
|
||||
'
|
||||
|
||||
if test -d .git -o -f .git &&
|
||||
VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
|
||||
case "$VN" in
|
||||
*$LF*) (exit 1) ;;
|
||||
v[0-9]*)
|
||||
git update-index -q --refresh
|
||||
test -z "$(git diff-index --name-only HEAD --)" ||
|
||||
VN="$VN-dirty" ;;
|
||||
esac
|
||||
then
|
||||
VN=$(echo "$VN" | sed -e 's/-/./g');
|
||||
else
|
||||
VN="$DEF_VER"
|
||||
fi
|
||||
|
||||
VN=$(expr "$VN" : v*'\(.*\)')
|
||||
|
||||
if test -r $VF
|
||||
then
|
||||
VC=$(sed -e 's/^VERSION=//' <$VF)
|
||||
else
|
||||
VC=unset
|
||||
fi
|
||||
test "$VN" = "$VC" || {
|
||||
echo >&2 "VERSION=$VN"
|
||||
echo "VERSION=$VN" >$VF
|
||||
}
|
||||
|
||||
|
||||
34
Makefile
Normal file
34
Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Makefile for todo.txt
|
||||
#
|
||||
|
||||
# Dynamically detect/generate version file as necessary
|
||||
# This file will define a variable called VERSION.
|
||||
.PHONY: .FORCE-VERSION-FILE
|
||||
VERSION-FILE: .FORCE-VERSION-FILE
|
||||
@./GEN-VERSION-FILE
|
||||
-include VERSION-FILE
|
||||
|
||||
# Maybe this will include the version in it.
|
||||
todo.sh: VERSION-FILE
|
||||
|
||||
# For packaging
|
||||
DISTFILES := todo.cfg
|
||||
|
||||
DISTNAME=todo.txt_cli-$(VERSION)
|
||||
dist: $(DISTFILES) todo.sh
|
||||
mkdir -p $(DISTNAME)
|
||||
cp -f $(DISTFILES) $(DISTNAME)/
|
||||
sed -e 's/@DEV_VERSION@/'$(VERSION)'/' todo.sh > $(DISTNAME)/todo.sh
|
||||
tar cf $(DISTNAME).tar $(DISTNAME)/
|
||||
gzip -f -9 $(DISTNAME).tar
|
||||
zip -9r $(DISTNAME).zip $(DISTNAME)/
|
||||
rm -r $(DISTNAME)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(DISTNAME).tar.gz $(DISTNAME).zip
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
@echo "TBD!"
|
||||
8
README
Normal file
8
README
Normal file
@@ -0,0 +1,8 @@
|
||||
TODO.TXT Command Line Interface
|
||||
Latest version: http://github.com/ginatrapani/todo.txt-cli/tree/master
|
||||
First release: 5/11/2006
|
||||
Conceived and released by: Gina Trapani (http://ginatrapani.org)
|
||||
Contributors: http://github.com/ginatrapani/todo.txt-cli/network
|
||||
License: GPL, http://www.gnu.org/copyleft/gpl.html
|
||||
More information and mailing list at http://todotxt.com
|
||||
To submit patches, fork the repository at http://github.com/ginatrapani/todo.txt-cli/tree/master
|
||||
78
index.html
78
index.html
@@ -1,78 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
|
||||
<title>Todo.txt CLI @ GitHub</title>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin-top: 1.0em;
|
||||
background-color: #CCC;
|
||||
font-family: "helvetica";
|
||||
color: #000;
|
||||
}
|
||||
#container {
|
||||
margin: 0 auto;
|
||||
width: 700px;
|
||||
}
|
||||
h1 { font-size: 3.8em; color: #5b3cf6; margin-bottom: 3px; }
|
||||
h1 .small { font-size: 0.4em; }
|
||||
h1 a { text-decoration: none }
|
||||
h2 { font-size: 1.5em; color: #5b3cf6; }
|
||||
h3 { text-align: center; color: #5b3cf6; }
|
||||
a { color: #5b3cf6; }
|
||||
.description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
|
||||
.download { float: right; }
|
||||
pre { background: #000; color: #fff; padding: 15px;}
|
||||
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
|
||||
.footer { text-align:center; padding-top:30px; font-style: italic; }
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<a href="http://github.com/ginatrapani/todo.txt-cli"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div class="download">
|
||||
<a href="http://github.com/ginatrapani/todo.txt-cli/zipball/master">
|
||||
<img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a>
|
||||
<a href="http://github.com/ginatrapani/todo.txt-cli/tarball/master">
|
||||
<img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a>
|
||||
</div>
|
||||
|
||||
<h1><a href="http://github.com/ginatrapani/todo.txt-cli">Todo.txt CLI</a> </h1>
|
||||
|
||||
<div class="description">
|
||||
A simple shell script for managing your todo.txt file. See more information at <a href="http://todotxt.com">Todotxt.com</a>.
|
||||
</div>
|
||||
|
||||
<h2>Contact</h2>
|
||||
<p>Join <a href="http://tech.groups.yahoo.com/group/todotxt/">the mailing list</a> for support or requests.
|
||||
<br/> </p>
|
||||
|
||||
|
||||
<h2>Download</h2>
|
||||
<p>
|
||||
You can download this project in either
|
||||
<a href="http://github.com/ginatrapani/todo.txt-cli/zipball/master">zip</a> or
|
||||
<a href="http://github.com/ginatrapani/todo.txt-cli/tarball/master">tar</a> formats.
|
||||
</p>
|
||||
<p>You can also clone the project with <a href="http://git-scm.com">Git</a>
|
||||
by running:
|
||||
<pre>$ git clone git://github.com/ginatrapani/todo.txt-cli</pre>
|
||||
</p>
|
||||
|
||||
<div class="footer">
|
||||
get the source code on GitHub : <a href="http://github.com/ginatrapani/todo.txt-cli">ginatrapani/todo.txt-cli</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
41
todo.cfg
Normal file
41
todo.cfg
Normal file
@@ -0,0 +1,41 @@
|
||||
# === EDIT FILE LOCATIONS BELOW ===
|
||||
|
||||
# Your todo.txt directory
|
||||
#export TODO_DIR="/Users/gina/Documents/todo"
|
||||
export TODO_DIR="C:/Documents and Settings/gina/My Documents"
|
||||
|
||||
# Your todo/done/report.txt locations
|
||||
export TODO_FILE="$TODO_DIR/todo.txt"
|
||||
export DONE_FILE="$TODO_DIR/done.txt"
|
||||
export REPORT_FILE="$TODO_DIR/report.txt"
|
||||
export TMP_FILE="$TODO_DIR/todo.tmp"
|
||||
|
||||
# == EDIT FILE LOCATIONS ABOVE ===
|
||||
|
||||
# === COLOR MAP ===
|
||||
|
||||
export NONE=''
|
||||
export BLACK='\\033[0;30m'
|
||||
export RED='\\033[0;31m'
|
||||
export GREEN='\\033[0;32m'
|
||||
export BROWN='\\033[0;33m'
|
||||
export BLUE='\\033[0;34m'
|
||||
export PURPLE='\\033[0;35m'
|
||||
export CYAN='\\033[0;36m'
|
||||
export LIGHT_GREY='\\033[0;37m'
|
||||
export DARK_GREY='\\033[1;30m'
|
||||
export LIGHT_RED='\\033[1;31m'
|
||||
export LIGHT_GREEN='\\033[1;32m'
|
||||
export YELLOW='\\033[1;33m'
|
||||
export LIGHT_BLUE='\\033[1;34m'
|
||||
export LIGHT_PURPLE='\\033[1;35m'
|
||||
export LIGHT_CYAN='\\033[1;36m'
|
||||
export WHITE='\\033[1;37m'
|
||||
export DEFAULT='\\033[0m'
|
||||
|
||||
# === PRIORITY COLORS ===
|
||||
|
||||
export PRI_A=$YELLOW # color for A priority
|
||||
export PRI_B=$GREEN # color for B priority
|
||||
export PRI_C=$LIGHT_BLUE # color for C priority
|
||||
export PRI_X=$WHITE # color for rest of them
|
||||
860
todo.sh
Executable file
860
todo.sh
Executable file
@@ -0,0 +1,860 @@
|
||||
#! /bin/bash
|
||||
|
||||
# NOTE: Todo.sh requires the todo.cfg configuration file to run.
|
||||
# Place the todo.cfg file in your home directory or use the -d option for a custom location.
|
||||
|
||||
[ -f VERSION-FILE ] && . VERSION-FILE || VERSION="@DEV_VERSION@"
|
||||
version() { sed -e 's/^ //' <<EndVersion
|
||||
TODO.TXT Command Line Interface v$VERSION
|
||||
|
||||
First release: 5/11/2006
|
||||
Original conception by: Gina Trapani (http://ginatrapani.org)
|
||||
Contributors: http://github.com/ginatrapani/todo.txt-cli/network
|
||||
License: GPL, http://www.gnu.org/copyleft/gpl.html
|
||||
More information and mailing list at http://todotxt.com
|
||||
Code repository: http://github.com/ginatrapani/todo.txt-cli/tree/master
|
||||
EndVersion
|
||||
exit 1
|
||||
}
|
||||
|
||||
oneline_usage="todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]"
|
||||
|
||||
usage()
|
||||
{
|
||||
sed -e 's/^ //' <<EndUsage
|
||||
Usage: $oneline_usage
|
||||
Try 'todo.sh -h' for more information.
|
||||
EndUsage
|
||||
exit 1
|
||||
}
|
||||
|
||||
shorthelp()
|
||||
{
|
||||
sed -e 's/^ //' <<EndHelp
|
||||
Usage: $oneline_usage
|
||||
|
||||
Actions:
|
||||
add|a "THING I NEED TO DO +project @context"
|
||||
addto DEST "TEXT TO ADD"
|
||||
append|app NUMBER "TEXT TO APPEND"
|
||||
archive
|
||||
command [ACTIONS]
|
||||
del|rm NUMBER [TERM]
|
||||
dp|depri NUMBER
|
||||
do NUMBER
|
||||
help
|
||||
list|ls [TERM...]
|
||||
listall|lsa [TERM...]
|
||||
listcon|lsc
|
||||
listfile|lf SRC [TERM...]
|
||||
listpri|lsp [PRIORITY]
|
||||
listproj|lsprj
|
||||
move|mv NUMBER DEST [SRC]
|
||||
prepend|prep NUMBER "TEXT TO PREPEND"
|
||||
pri|p NUMBER PRIORITY
|
||||
replace NUMBER "UPDATED TODO"
|
||||
report
|
||||
|
||||
See "help" for more details.
|
||||
EndHelp
|
||||
exit 0
|
||||
}
|
||||
|
||||
help()
|
||||
{
|
||||
sed -e 's/^ //' <<EndHelp
|
||||
Usage: $oneline_usage
|
||||
|
||||
Actions:
|
||||
add "THING I NEED TO DO +project @context"
|
||||
a "THING I NEED TO DO +project @context"
|
||||
Adds THING I NEED TO DO to your todo.txt file on its own line.
|
||||
Project and context notation optional.
|
||||
Quotes optional.
|
||||
|
||||
addto DEST "TEXT TO ADD"
|
||||
Adds a line of text to any file located in the todo.txt directory.
|
||||
For example, addto inbox.txt "decide about vacation"
|
||||
|
||||
append NUMBER "TEXT TO APPEND"
|
||||
app NUMBER "TEXT TO APPEND"
|
||||
Adds TEXT TO APPEND to the end of the todo on line NUMBER.
|
||||
Quotes optional.
|
||||
|
||||
archive
|
||||
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]
|
||||
rm NUMBER [TERM]
|
||||
Deletes the item on line NUMBER in todo.txt.
|
||||
If term specified, deletes only the term from the line.
|
||||
|
||||
depri NUMBER
|
||||
dp NUMBER
|
||||
Deprioritizes (removes the priority) from the item
|
||||
on line NUMBER in todo.txt.
|
||||
|
||||
do NUMBER
|
||||
Marks item on line NUMBER as done in todo.txt.
|
||||
|
||||
help
|
||||
Display this help message.
|
||||
|
||||
list [TERM...]
|
||||
ls [TERM...]
|
||||
Displays all todo's that contain TERM(s) sorted by priority with line
|
||||
numbers. If no TERM specified, lists entire todo.txt.
|
||||
|
||||
listall [TERM...]
|
||||
lsa [TERM...]
|
||||
Displays all the lines in todo.txt AND done.txt that contain TERM(s)
|
||||
sorted by priority with line numbers. If no TERM specified, lists
|
||||
entire todo.txt AND done.txt concatenated and sorted.
|
||||
|
||||
listcon
|
||||
lsc
|
||||
Lists all the task contexts that start with the @ sign in todo.txt.
|
||||
|
||||
listfile SRC [TERM...]
|
||||
lf SRC [TERM...]
|
||||
Displays all the lines in SRC file located in the todo.txt directory,
|
||||
sorted by priority with line numbers. If TERM specified, lists
|
||||
all lines that contain TERM in SRC file.
|
||||
|
||||
listpri [PRIORITY]
|
||||
lsp [PRIORITY]
|
||||
Displays all items prioritized PRIORITY.
|
||||
If no PRIORITY specified, lists all prioritized items.
|
||||
|
||||
listproj
|
||||
lsprj
|
||||
Lists all the projects that start with the + sign in todo.txt.
|
||||
|
||||
move NUMBER DEST [SRC]
|
||||
mv NUMBER DEST [SRC]
|
||||
Moves a line from source text file (SRC) to destination text file (DEST).
|
||||
Both source and destination file must be located in the directory defined
|
||||
in the configuration directory. When SRC is not defined
|
||||
it's by default todo.txt.
|
||||
|
||||
prepend NUMBER "TEXT TO PREPEND"
|
||||
prep NUMBER "TEXT TO PREPEND"
|
||||
Adds TEXT TO PREPEND to the beginning of the todo on line NUMBER.
|
||||
Quotes optional.
|
||||
|
||||
pri NUMBER PRIORITY
|
||||
p NUMBER PRIORITY
|
||||
Adds PRIORITY to todo on line NUMBER. If the item is already
|
||||
prioritized, replaces current priority with new PRIORITY.
|
||||
PRIORITY must be an uppercase letter between A and Z.
|
||||
|
||||
replace NUMBER "UPDATED TODO"
|
||||
Replaces todo on line NUMBER with UPDATED TODO.
|
||||
|
||||
report
|
||||
Adds the number of open todo's and closed done's to report.txt.
|
||||
|
||||
|
||||
|
||||
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
|
||||
Use a configuration file other than the default ~/todo.cfg
|
||||
-f
|
||||
Forces actions without confirmation or interactive input
|
||||
-h
|
||||
Display a short help message
|
||||
-p
|
||||
Plain mode turns off colors
|
||||
-P
|
||||
Hide priority labels in list output. Use twice to show
|
||||
priority labels (default).
|
||||
-a
|
||||
Don't auto-archive tasks automatically on completion
|
||||
-n
|
||||
Don't preserve line numbers; automatically remove blank lines
|
||||
on task deletion
|
||||
-t
|
||||
Prepend the current date to a task automatically
|
||||
when it's added.
|
||||
-v
|
||||
Verbose mode turns on confirmation messages
|
||||
-vv
|
||||
Extra verbose mode prints some debugging information
|
||||
-V
|
||||
Displays version, license and credits
|
||||
|
||||
|
||||
Environment variables:
|
||||
TODOTXT_AUTO_ARCHIVE=0 is same as option -a
|
||||
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE
|
||||
TODOTXT_FORCE=1 is same as option -f
|
||||
TODOTXT_PRESERVE_LINE_NUMBERS=0 is same as option -n
|
||||
TODOTXT_PLAIN=1 is same as option -p
|
||||
TODOTXT_DATE_ON_ADD=1 is same as option -t
|
||||
TODOTXT_VERBOSE=1 is same as option -v
|
||||
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
|
||||
EndHelp
|
||||
|
||||
if [ -d "$HOME/.todo.actions.d" ]
|
||||
then
|
||||
echo ""
|
||||
for action in $HOME/.todo.actions.d/*
|
||||
do
|
||||
if [ -x $action ]
|
||||
then
|
||||
$action usage
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
die()
|
||||
{
|
||||
echo "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup()
|
||||
{
|
||||
[ -f "$TMP_FILE" ] && rm "$TMP_FILE"
|
||||
exit 0
|
||||
}
|
||||
|
||||
archive()
|
||||
{
|
||||
#defragment blank lines
|
||||
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
cp "$TODO_FILE" "$TMP_FILE"
|
||||
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
||||
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
|
||||
cleanup
|
||||
}
|
||||
|
||||
|
||||
# == PROCESS OPTIONS ==
|
||||
while getopts ":fhpnatvV+@Pd:" Option
|
||||
do
|
||||
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
|
||||
export 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
|
||||
export HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
||||
fi
|
||||
;;
|
||||
a )
|
||||
TODOTXT_AUTO_ARCHIVE=0
|
||||
;;
|
||||
d )
|
||||
TODOTXT_CFG_FILE=$OPTARG
|
||||
;;
|
||||
f )
|
||||
TODOTXT_FORCE=1
|
||||
;;
|
||||
h )
|
||||
shorthelp
|
||||
;;
|
||||
n )
|
||||
TODOTXT_PRESERVE_LINE_NUMBERS=0
|
||||
;;
|
||||
p )
|
||||
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
|
||||
export HIDE_PRIORITY_SUBSTITUTION="([A-Z])[[:space:]]"
|
||||
fi
|
||||
;;
|
||||
t )
|
||||
TODOTXT_DATE_ON_ADD=1
|
||||
;;
|
||||
v )
|
||||
: $(( TODOTXT_VERBOSE++ ))
|
||||
;;
|
||||
V )
|
||||
version
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
# defaults if not yet defined
|
||||
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
|
||||
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
|
||||
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/todo.cfg}
|
||||
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_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
|
||||
|
||||
[ -e "$TODOTXT_CFG_FILE" ] || {
|
||||
CFG_FILE_ALT="$HOME/.todo.cfg"
|
||||
|
||||
if [ -e "$CFG_FILE_ALT" ]
|
||||
then
|
||||
TODOTXT_CFG_FILE="$CFG_FILE_ALT"
|
||||
fi
|
||||
}
|
||||
|
||||
export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD
|
||||
|
||||
TODO_SH="$0"
|
||||
export TODO_SH
|
||||
|
||||
# === SANITY CHECKS (thanks Karl!) ===
|
||||
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE"
|
||||
|
||||
. "$TODOTXT_CFG_FILE"
|
||||
|
||||
ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
||||
|
||||
[ -z "$ACTION" ] && usage
|
||||
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
||||
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $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 "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
||||
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
||||
|
||||
if [ $TODOTXT_PLAIN = 1 ]; then
|
||||
PRI_A=$NONE
|
||||
PRI_B=$NONE
|
||||
PRI_C=$NONE
|
||||
PRI_X=$NONE
|
||||
DEFAULT=$NONE
|
||||
fi
|
||||
|
||||
# === HEAVY LIFTING ===
|
||||
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 the file, then run the filter command,
|
||||
## then sort and mangle output some more
|
||||
items=$(
|
||||
sed = "$src" \
|
||||
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||
| grep -v "^[0-9]\+ *$"
|
||||
)
|
||||
if [ "${filter_command}" ]; then
|
||||
filtered_items=$(echo -ne "$items" | eval ${filter_command})
|
||||
else
|
||||
filtered_items=$items
|
||||
fi
|
||||
filtered_items=$(
|
||||
echo -ne "$filtered_items" \
|
||||
| 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 "$filtered_items${filtered_items:+\n}"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
NUMTASKS=$( echo -ne "$filtered_items" | sed -n '$ =' )
|
||||
TOTALTASKS=$( echo -ne "$items" | sed -n '$ =' )
|
||||
|
||||
echo "--"
|
||||
echo "TODO: ${NUMTASKS:-0} of ${TOTALTASKS:-0} 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 ==
|
||||
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
|
||||
"add" | "a")
|
||||
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "Add: "
|
||||
read input
|
||||
else
|
||||
[ -z "$2" ] && die "usage: $0 add \"TODO ITEM\""
|
||||
shift
|
||||
input=$*
|
||||
fi
|
||||
|
||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||
now=`date '+%Y-%m-%d'`
|
||||
input="$now $input"
|
||||
fi
|
||||
echo "$input" >> "$TODO_FILE"
|
||||
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
|
||||
cleanup;;
|
||||
|
||||
"addto" )
|
||||
[ -z "$2" ] && die "usage: $0 addto DEST \"TODO ITEM\""
|
||||
dest="$TODO_DIR/$2"
|
||||
[ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\""
|
||||
shift
|
||||
shift
|
||||
input=$*
|
||||
|
||||
if [ -f "$dest" ]; then
|
||||
echo "$input" >> "$dest"
|
||||
TASKNUM=$(sed -n '$ =' "$dest")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added to $dest on line $TASKNUM."
|
||||
else
|
||||
echo "TODO: Destination file $dest does not exist."
|
||||
fi
|
||||
cleanup;;
|
||||
|
||||
"append" | "app" )
|
||||
errmsg="usage: $0 append ITEM# \"TEXT TO APPEND\""
|
||||
shift; item=$1; shift
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "$item: No such todo."
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "Append: "
|
||||
read input
|
||||
else
|
||||
input=$*
|
||||
fi
|
||||
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||
else
|
||||
echo "TODO: Error appending task $item."
|
||||
fi
|
||||
cleanup;;
|
||||
|
||||
"archive" )
|
||||
archive;;
|
||||
|
||||
"del" | "rm" )
|
||||
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||
errmsg="usage: $0 del ITEM#"
|
||||
item=$2
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
if sed -ne "$item p" "$TODO_FILE" | grep "^."; then
|
||||
DELETEME=$(sed "$2!d" "$TODO_FILE")
|
||||
|
||||
if [ $TODOTXT_FORCE = 0 ]; then
|
||||
echo "Delete '$DELETEME'? (y/n)"
|
||||
read ANSWER
|
||||
else
|
||||
ANSWER="y"
|
||||
fi
|
||||
if [ "$ANSWER" = "y" ]; then
|
||||
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||
# delete line (changes line numbers)
|
||||
sed -i.bak -e $2"s/^.*//" -e '/./!d' "$TODO_FILE"
|
||||
else
|
||||
# leave blank line behind (preserves line numbers)
|
||||
sed -i.bak -e $2"s/^.*//" "$TODO_FILE"
|
||||
fi
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
|
||||
cleanup
|
||||
else
|
||||
echo "TODO: No tasks were deleted."
|
||||
fi
|
||||
else
|
||||
echo "$item: No such todo."
|
||||
fi
|
||||
else
|
||||
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
|
||||
fi ;;
|
||||
|
||||
"depri" | "dp" )
|
||||
item=$2
|
||||
errmsg="usage: $0 depri ITEM#"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "$item: No such todo."
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
sed -e $item"s/^(.*) //" "$TODO_FILE" > /dev/null 2>&1
|
||||
|
||||
if [ "$?" -eq 0 ]; then
|
||||
#it's all good, continue
|
||||
sed -i.bak -e $2"s/^(.*) //" "$TODO_FILE"
|
||||
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item deprioritized."
|
||||
cleanup
|
||||
else
|
||||
die "$errmsg"
|
||||
fi;;
|
||||
|
||||
"do" )
|
||||
errmsg="usage: $0 do ITEM#"
|
||||
item=$2
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "$item: No such todo."
|
||||
|
||||
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"
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
|
||||
|
||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||
archive
|
||||
fi
|
||||
cleanup ;;
|
||||
|
||||
"help" )
|
||||
help
|
||||
;;
|
||||
|
||||
"list" | "ls" )
|
||||
shift ## Was ls; new $1 is first search term
|
||||
_list "$TODO_FILE" "$@"
|
||||
|
||||
cleanup
|
||||
;;
|
||||
|
||||
"listall" | "lsa" )
|
||||
shift ## Was lsa; new $1 is first search term
|
||||
|
||||
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||
_list "$TMP_FILE" "$@"
|
||||
|
||||
cleanup
|
||||
;;
|
||||
|
||||
"listfile" | "lf" )
|
||||
shift ## Was listfile, next $1 is file name
|
||||
FILE="$1"
|
||||
shift ## Was filename; next $1 is first search term
|
||||
|
||||
_list "$FILE" "$@"
|
||||
|
||||
cleanup
|
||||
;;
|
||||
|
||||
"listcon" | "lsc" )
|
||||
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq
|
||||
cleanup ;;
|
||||
|
||||
"listproj" | "lsprj" )
|
||||
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '+' | sort | uniq
|
||||
cleanup ;;
|
||||
|
||||
|
||||
"listpri" | "lsp" )
|
||||
shift ## was "listpri", new $1 is priority to list
|
||||
|
||||
if [ "${1:-}" ]
|
||||
then
|
||||
## A priority was specified
|
||||
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
|
||||
die "usage: $0 listpri PRIORITY
|
||||
note: PRIORITY must a single letter from A to Z."
|
||||
}
|
||||
else
|
||||
## No priority specified; show all priority tasks
|
||||
pri="[[:upper:]]"
|
||||
fi
|
||||
pri="($pri)"
|
||||
|
||||
_list "$TODO_FILE" "$pri"
|
||||
;;
|
||||
|
||||
"move" | "mv" )
|
||||
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||
errmsg="usage: $0 mv ITEM# DEST [SRC]"
|
||||
item=$2
|
||||
dest="$TODO_DIR/$3"
|
||||
src="$TODO_DIR/$4"
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[ -z "$4" ] && src="$TODO_FILE"
|
||||
[ -z "$dest" ] && die "$errmsg"
|
||||
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
if [ -f "$src" ]; then
|
||||
if [ -f "$dest" ]; then
|
||||
if sed -ne "$item p" "$src" | grep "^."; then
|
||||
MOVEME=$(sed "$item!d" "$src")
|
||||
if [ $TODOTXT_FORCE = 0 ]; then
|
||||
echo "Move '$MOVEME' from $src to $dest? (y/n)"
|
||||
read ANSWER
|
||||
else
|
||||
ANSWER="y"
|
||||
fi
|
||||
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"
|
||||
else
|
||||
# leave blank line behind (preserves line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" "$src"
|
||||
fi
|
||||
echo "$MOVEME" >> "$dest"
|
||||
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
||||
cleanup
|
||||
else
|
||||
echo "TODO: No tasks moved."
|
||||
fi
|
||||
else
|
||||
echo "$item: No such item in $src."
|
||||
fi
|
||||
else
|
||||
echo "TODO: Destination file $dest does not exist."
|
||||
fi
|
||||
else
|
||||
echo "TODO: Source file $src does not exist."
|
||||
fi
|
||||
cleanup;;
|
||||
|
||||
"prepend" | "prep" )
|
||||
errmsg="usage: $0 prepend ITEM# \"TEXT TO PREPEND\""
|
||||
shift; item=$1; shift
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "$item: No such todo."
|
||||
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "Prepend: "
|
||||
read input
|
||||
else
|
||||
input=$*
|
||||
fi
|
||||
|
||||
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||
else
|
||||
echo "TODO: Error prepending task $item."
|
||||
fi
|
||||
cleanup;;
|
||||
|
||||
"pri" | "p" )
|
||||
item=$2
|
||||
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
|
||||
|
||||
errmsg="usage: $0 pri ITEM# PRIORITY
|
||||
note: PRIORITY must be anywhere from A to Z."
|
||||
|
||||
[ "$#" -ne 3 ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
[[ "$newpri" = +([A-Z]) ]] || die "$errmsg"
|
||||
|
||||
sed -e $item"s/^(.*) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1
|
||||
|
||||
if [ "$?" -eq 0 ]; then
|
||||
#it's all good, continue
|
||||
sed -i.bak -e $2"s/^(.*) //" -e $2"s/^/($newpri) /" "$TODO_FILE"
|
||||
NEWTODO=$(sed "$2!d" "$TODO_FILE")
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item prioritized ($newpri)."
|
||||
cleanup
|
||||
else
|
||||
die "$errmsg"
|
||||
fi;;
|
||||
|
||||
"replace" )
|
||||
errmsg="usage: $0 replace ITEM# \"UPDATED ITEM\""
|
||||
shift; item=$1; shift
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "$item: No such todo."
|
||||
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "Replacement: "
|
||||
read input
|
||||
else
|
||||
input=$*
|
||||
fi
|
||||
|
||||
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $NEWTODO"
|
||||
cleanup;;
|
||||
|
||||
"report" )
|
||||
#archive first
|
||||
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
||||
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||
|
||||
NUMLINES=$( sed -n '$ =' "$TODO_FILE" )
|
||||
if [ ${NUMLINES:-0} = "0" ]; then
|
||||
echo "datetime todos dones" >> "$REPORT_FILE"
|
||||
fi
|
||||
#now report
|
||||
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
|
||||
echo ${TDONE:-0})
|
||||
echo $TECHO >> "$REPORT_FILE"
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||
cat "$REPORT_FILE"
|
||||
cleanup;;
|
||||
|
||||
* )
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user