@@ -11,25 +11,75 @@ Actions:
11
11
init Create \` todo\` repo
12
12
home Open \` issues\` in browser
13
13
add Add todo item
14
- edit Open \` issue\` in browser
14
+ view/ edit Open \` issue\` in browser
15
15
done Close \` issue\`
16
16
list Show todo list
17
17
18
+ Options:
19
+ --version Show version
20
+ --help Show help for command
21
+ --scope TODO scope, default: today(yyyy-MM-dd).
22
+ Support [yesterday, tommorow, weekly, monthly, yearly].
23
+ Any other will be used directly as issue title.
18
24
Examples:
19
25
gh todo add abc
20
26
EOF
21
27
}
22
28
23
29
version=" 0.3.0"
24
- today= $( date + " %Y-%m-%d " )
30
+
25
31
repo=" $( gh config get -h github.com user) /todo"
26
32
27
33
if [ -n " $GH_TODO_REPO " ]; then
28
34
repo=" $GH_TODO_REPO "
29
35
fi
30
36
37
+ # parse `--scope` option
38
+ POSITIONAL=()
39
+ while [[ $# -gt 0 ]]; do
40
+ key=" $1 "
41
+
42
+ case $key in
43
+ --scope)
44
+ scope=" $2 "
45
+ shift # past argument
46
+ shift # past value
47
+ ;;
48
+ * ) # unknown option
49
+ POSITIONAL+=(" $1 " ) # save it in an array for later
50
+ shift # past argument
51
+ ;;
52
+ esac
53
+ done
54
+ set -- " ${POSITIONAL[@]} " # restore positional parameters
55
+
56
+ issue_title=$( date +" %Y-%m-%d" )
57
+ # get issue id by `--scope`
31
58
get_issue_id () {
32
- gh issue list --search " $today " --json " number" --jq " .[0].number" --repo $repo
59
+ if [ -n " $scope " ]; then
60
+ case " $scope " in
61
+ yesterday)
62
+ issue_title=$( date -v-1d +" %Y-%m-%d" )
63
+ ;;
64
+ tommorow)
65
+ issue_title=$( date -v+1d +" %Y-%m-%d" )
66
+ ;;
67
+ week)
68
+ issue_title=" Week: $( date -v -Mon +" %Y-%m-%d" ) ~ $( date -v -Mon -v+6d +" %Y-%m-%d" ) "
69
+ ;;
70
+ month)
71
+ issue_title=" Month: $( date +" %Y-%m" ) "
72
+ ;;
73
+ year)
74
+ issue_title=" Year: $( date +" %Y" ) "
75
+ ;;
76
+ * )
77
+ issue_title=$scope
78
+ ;;
79
+ esac
80
+ fi
81
+
82
+ gh issue list --search " $issue_title " --json " number" --jq " .[0].number" --repo $repo
33
83
}
34
84
35
85
init () {
@@ -44,9 +94,9 @@ add() {
44
94
input=" $1 "
45
95
issue_id=$( get_issue_id)
46
96
if [[ -z $issue_id ]]; then
47
- exec gh issue create --title $today --body " - [ ] $input " --repo $repo
97
+ exec gh issue create --title $issue_title --body " - [ ] $input " --repo $repo
48
98
else
49
- body=$( gh issue list --search " $today " --json " body" --jq " .[0].body" --repo $repo )
99
+ body=$( gh issue list --search " $issue_title " --json " body" --jq " .[0].body" --repo $repo )
50
100
body=$( echo -e " $body \n- [ ] $input " )
51
101
exec gh issue edit $issue_id --body " $body " --repo $repo
52
102
fi
@@ -55,15 +105,15 @@ add() {
55
105
edit () {
56
106
issue_id=$( get_issue_id)
57
107
if [[ -z $issue_id ]]; then
58
- echo " No plans for today yet."
108
+ echo " No plans for $issue_title yet."
59
109
fi
60
110
exec gh issue view $issue_id --repo $repo --web
61
111
}
62
112
63
113
_done () {
64
114
issue_id=$( get_issue_id)
65
115
if [[ -z $issue_id ]]; then
66
- echo " No plans for today yet."
116
+ echo " No plans for $issue_title yet."
67
117
else
68
118
exec gh issue close $issue_id --repo $repo
69
119
fi
@@ -72,7 +122,7 @@ _done() {
72
122
list () {
73
123
issue_id=$( get_issue_id)
74
124
if [[ -z $issue_id ]]; then
75
- echo " No plans for today yet."
125
+ echo " No plans for $issue_title yet."
76
126
else
77
127
exec gh issue view $issue_id --repo $repo
78
128
fi
@@ -112,15 +162,16 @@ while [ $# -gt 0 ]; do
112
162
fi
113
163
add " $input "
114
164
;;
115
- edit)
165
+ view | edit)
116
166
shift
117
- edit $@
167
+ edit
118
168
;;
119
169
done)
120
170
shift
121
- _done $@
171
+ _done
122
172
;;
123
173
list)
174
+ shift
124
175
list
125
176
;;
126
177
* )
0 commit comments