forked from todotxt/todo.txt-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedit
executable file
·73 lines (65 loc) · 1.78 KB
/
edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#
# works on cygwin and OS X 10.4
#
action=$1
# now shift the positional parameters to the right, past
# the plug-in action, so that they can be pasted to the
# built-in actions.
#
shift
[ "$action" = "usage" ] && [[ "$1" == "version" ]] && {
sed -e 's/^ //' <<EndVersion
edit Add-on, version 1.0.2.
First release: 9-APR-2009
Author: Dave Hein
License: GPL, http://www.gnu.org/copyleft/gpl.html
EndVersion
exit
}
[ "$action" = "usage" ] && [[ "$1" == "short" ]] && {
sed -e 's/^ //' <<EndUsage
edit [todo|done|cfg]
EndUsage
exit
}
[ "$action" = "usage" ] && {
sed -e 's/^ //' <<EndUsage
edit [todo|done|cfg]
edit [item]
Edits either the todo.txt, done.txt, or
todo.cfg files. If no arg is supplied, todo.txt
will be edited. If a numeric item number is
supplied, the todo.txt is edited, with the cursor
sitting on that line (assuming you use vi or emacs).
The editor invoked uses the EDITOR environment
variable, or defaults to vi.
EndUsage
exit
}
# see if an editor was supplied
#
TODO_EDITOR_=${EDITOR:-vi}
# see which file, if any was specified
#
TODO_CURSOR_LINE_=
if [ x"$1" == x ] ; then
TODO_EDIT_FILE_="$TODO_DIR/todo.txt"
elif echo "$1" | grep -iq ^[0-9][0-9]*$ ; then
TODO_EDIT_FILE_="$TODO_DIR/todo.txt"
TODO_CURSOR_LINE_="+$1"
elif echo "$1" | grep -iq ^todo$ ; then
TODO_EDIT_FILE_="$TODO_DIR/todo.txt"
elif echo "$1" | grep -iq ^done$ ; then
TODO_EDIT_FILE_="$TODO_DIR/done.txt"
elif echo "$1" | grep -iq ^cfg$ ; then
TODO_EDIT_FILE_="$TODOTXT_CFG_FILE"
else
echo "'$1' is an invalid argument."
exit
fi
# edit the file
#
#echo "$TODO_EDITOR_" $TODO_CURSOR_LINE_ "$TODO_EDIT_FILE_"
"$TODO_EDITOR_" $TODO_CURSOR_LINE_ "$TODO_EDIT_FILE_"
exit