tot 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/tot +5 -0
- data/lib/tot/version.rb +3 -0
- data/lib/tot.rb +217 -0
- data/tot.gemspec +25 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzAyYWZmMTcyMjE3YzZiNTYzNjM2MTQ5OThjNTBkMDA5MjM2MzI5Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTNiMWQyZWM3Y2EwODE1ZDA0ZDVmYjJmZjcxZDQyMjMwY2I5YmNhZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWQ0NWViNmI1MGNhNzk1MzcwZmQyMGUxZmIyOTg3OGE3MWJmNjI5NjhjNGQy
|
10
|
+
MGRkYmU2OWMzODM4ZDJlM2FmOGZhZWMxZjBkYjgwYzI4NThmMjYyNzJkYjBl
|
11
|
+
N2U3ZDRjN2YzNTk2MWQ1NTlmZThjYTk5N2E0YjhmNzE4MTE1Mzk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTI3MTVmYjhhM2Q1OWY3MWUxMjFkMDg5ZDQ2NDI2YjFjYmFkNWU1MTE1OGYw
|
14
|
+
OWI3MTBhZjExNWRkNGQ3NzAyOThmNzdhMTZhNTAwMjFlMmIyMWU5NjBhZTkz
|
15
|
+
ODFjNzU2YzRmMzhkNjRkZTBlZWE4NDc0MzgyMDE5YWExNTg5YjA=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Shohei Fujii
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Tot
|
2
|
+
|
3
|
+
Manage your todo on your terminal.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tot'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tot
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Please see
|
22
|
+
|
23
|
+
$ tot help
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/tot
ADDED
data/lib/tot/version.rb
ADDED
data/lib/tot.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "tot/version"
|
3
|
+
require "thor"
|
4
|
+
require "readline"
|
5
|
+
require "fileutils"
|
6
|
+
require "yaml"
|
7
|
+
require "time"
|
8
|
+
require "term/ansicolor"
|
9
|
+
|
10
|
+
module Tot
|
11
|
+
module Config #{{{
|
12
|
+
@@CONFIG_FILE = File.join(ENV['HOME'],'.totrc')
|
13
|
+
@@TODO_PATH = nil
|
14
|
+
def todo_path
|
15
|
+
create unless File.exists?(@@CONFIG_FILE)
|
16
|
+
@@TODO_PATH = YAML.load_file(@@CONFIG_FILE)['todo_file']
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
path = Readline.readline("Input the path to save tasks >> ",false)
|
21
|
+
path += ".yaml" unless [".yaml",".yml"].include?(File.extname(path))
|
22
|
+
File.open(@@CONFIG_FILE,'w'){|file| YAML.dump({'todo_file' => path}, file)}
|
23
|
+
end
|
24
|
+
module_function :todo_path,:create
|
25
|
+
end #}}}
|
26
|
+
|
27
|
+
class TodoManager #{{{
|
28
|
+
include Enumerable
|
29
|
+
def initialize
|
30
|
+
load_file
|
31
|
+
end
|
32
|
+
def load_file
|
33
|
+
todo_path = Config.todo_path
|
34
|
+
File.open(todo_path,'w'){|file| YAML.dump([],file)} unless File.exists? todo_path
|
35
|
+
@tasks = YAML.load_file(todo_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def dump
|
39
|
+
#File.open(Config.todo_path,'w'){|file| file.puts todos.ya2yaml} #YAML.dump(todos, file)}
|
40
|
+
# ya2yamlだとhashの順番が変わる
|
41
|
+
File.open(Config.todo_path,'w'){|file| YAML.dump(@tasks, file)}
|
42
|
+
end
|
43
|
+
|
44
|
+
def each
|
45
|
+
@tasks = load_file.sort_by{|i| i['date']}
|
46
|
+
@tasks.each do |todo|
|
47
|
+
yield todo
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def add(new_todo)
|
53
|
+
@tasks = load_file
|
54
|
+
@tasks.push new_todo
|
55
|
+
dump
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete(at)
|
59
|
+
@tasks = load_file
|
60
|
+
@tasks.delete_at(at)
|
61
|
+
dump
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_at(at)
|
65
|
+
@tasks.delete_at at
|
66
|
+
end
|
67
|
+
def print_color(with_index = false) #{{{
|
68
|
+
@tasks.each_with_index do |todo,idx|
|
69
|
+
#https://github.com/flori/term-ansicolor/blob/master/examples/example.rb
|
70
|
+
case (Date.parse(todo['date'].to_s) - Date.parse(Time.now.to_s)).to_i
|
71
|
+
when -10 .. -1
|
72
|
+
print Term::ANSIColor.cyan
|
73
|
+
when 0..1
|
74
|
+
print Term::ANSIColor.bold, Term::ANSIColor.red
|
75
|
+
when 2..3
|
76
|
+
print Term::ANSIColor.yellow
|
77
|
+
else
|
78
|
+
print Term::ANSIColor.white
|
79
|
+
end
|
80
|
+
|
81
|
+
puts [("<<#{idx}>>" if with_index),
|
82
|
+
todo['date'].strftime("%Y/%m/%d %H:%M"),
|
83
|
+
todo['title'],
|
84
|
+
['[',todo['tag'],']'].flatten.join(' ')].join(' ')
|
85
|
+
print Term::ANSIColor.reset
|
86
|
+
end
|
87
|
+
self
|
88
|
+
end #}}}
|
89
|
+
#module_function :load_file, :dump, :listup, :add
|
90
|
+
end #}}}
|
91
|
+
|
92
|
+
module Utils #{{{
|
93
|
+
def datetime_filter(buf) #{{{
|
94
|
+
today = DateTime.now
|
95
|
+
ret = nil
|
96
|
+
case buf
|
97
|
+
when /^(今日)/
|
98
|
+
ret = today
|
99
|
+
when /^(明日|あした|あす)/
|
100
|
+
ret = today + 1
|
101
|
+
when /^(明後日|あさって)/
|
102
|
+
ret = today + 2
|
103
|
+
when /^しあさって/
|
104
|
+
ret = today + 3
|
105
|
+
when /^(日|月|火|水|木|金|土)曜(日)?/
|
106
|
+
# 次の○曜日
|
107
|
+
date_offset = ([ '日', '月', '火', '水', '木', '金', '土' ].index($1) - today.wday + 7) % 7
|
108
|
+
date_offset += 7 if date_offset == 0
|
109
|
+
ret = today + date_offset
|
110
|
+
when /^([0-9]+\/[0-9]+\/[0-9]+)/# yyyy/mm/dd
|
111
|
+
ret = DateTime.parse($1)
|
112
|
+
when /^([0-9]+\/[0-9]+)/# mm/dd
|
113
|
+
date = DateTime.parse($1)
|
114
|
+
# 過去の日付だったら来年にする
|
115
|
+
while date < today
|
116
|
+
date = date >> 12
|
117
|
+
end
|
118
|
+
ret = date
|
119
|
+
when /^([0-9]+)/# mmddd
|
120
|
+
datestr = $1
|
121
|
+
case datestr.length
|
122
|
+
when 2
|
123
|
+
# 12 => 1/2
|
124
|
+
datestr = datestr.slice(0..0) + "/" + datestr.slice(1..1)
|
125
|
+
when 3
|
126
|
+
# 123 => 1/23 ※ 12/3 の可能性もあるけどそうはしない
|
127
|
+
datestr = datestr.slice(0..0) + "/" + datestr.slice(1..2)
|
128
|
+
when 4
|
129
|
+
# 1230 => 12/30
|
130
|
+
datestr = datestr.slice(0..1) + "/" + datestr.slice(2..3)
|
131
|
+
else
|
132
|
+
raise ArgumentError , "不正な値です"
|
133
|
+
end
|
134
|
+
date = DateTime.parse(datestr)
|
135
|
+
# 過去の日付だったら来年にする
|
136
|
+
while date < today
|
137
|
+
date = date >> 12
|
138
|
+
end
|
139
|
+
ret = date
|
140
|
+
end
|
141
|
+
ret
|
142
|
+
end #}}}
|
143
|
+
|
144
|
+
module_function :datetime_filter
|
145
|
+
end #}}}
|
146
|
+
|
147
|
+
class CLI < Thor
|
148
|
+
def initialize(*args)
|
149
|
+
super
|
150
|
+
@todo_manager = TodoManager.new
|
151
|
+
end
|
152
|
+
|
153
|
+
desc 'list' , 'list up your todo'
|
154
|
+
method_option :tag, :type => :array
|
155
|
+
def list
|
156
|
+
@todo_manager.each do |todo|
|
157
|
+
unless options[:tag].nil?
|
158
|
+
options[:tag].all?{|i| todo['tag'].include? i}
|
159
|
+
else
|
160
|
+
true
|
161
|
+
end
|
162
|
+
end.print_color(false)
|
163
|
+
end
|
164
|
+
|
165
|
+
desc 'add' , 'add a task'
|
166
|
+
def add
|
167
|
+
new_todo = {}
|
168
|
+
new_todo['title'] = Readline.readline('title> ', true).chomp('\n')
|
169
|
+
new_todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
|
170
|
+
new_todo['tag'] = Readline.readline('tag (separate by space)> ', true)
|
171
|
+
.chomp('\n').split(' ')
|
172
|
+
tmpfile = "/tmp/tot.markdown"
|
173
|
+
# File.open(tmpfile,"w"){|file|
|
174
|
+
# file.puts "\n\n# This line will be ignored."
|
175
|
+
# }
|
176
|
+
system([ENV['EDITOR'],tmpfile].join(' '))
|
177
|
+
new_todo['text'] = File.readlines(tmpfile).join
|
178
|
+
print new_todo['text']
|
179
|
+
@todo_manager.add new_todo
|
180
|
+
end
|
181
|
+
|
182
|
+
desc 'delete', 'delete a task'
|
183
|
+
def delete
|
184
|
+
@todo_manager.print_color(true)
|
185
|
+
@todo_manager.delete_at Readline.readline('Which Task?> ',false).chomp('\n').to_i
|
186
|
+
@todo_manager.dump
|
187
|
+
end
|
188
|
+
|
189
|
+
desc 'show TITLE', <<-EOF
|
190
|
+
show the detail of a task.
|
191
|
+
TITLE does not need to be complete.
|
192
|
+
EOF
|
193
|
+
def show(title)
|
194
|
+
reg = Regexp.new(title,Regexp::IGNORECASE)
|
195
|
+
todos = @todo_manager.find_all{|item| reg.match(item['title'])}
|
196
|
+
if todos.size == 0
|
197
|
+
puts 'No matched task.'
|
198
|
+
elsif todos.size > 1
|
199
|
+
puts 'Several tasks matched.'
|
200
|
+
else
|
201
|
+
todo = todos[0]
|
202
|
+
puts 'Title: ' + todo['title']
|
203
|
+
puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
|
204
|
+
puts
|
205
|
+
print todo['text']
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
desc 'edit TITLE', 'edit a task'
|
211
|
+
method_options :text => :boolean, :title => :boolean, :date => :title
|
212
|
+
def edit
|
213
|
+
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
data/tot.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tot"
|
8
|
+
spec.version = Tot::VERSION
|
9
|
+
spec.authors = ["Shohei Fujii"]
|
10
|
+
spec.email = ["fujii.shohei@gmail.com"]
|
11
|
+
spec.description = %q{Todo on Terminal}
|
12
|
+
spec.summary = %q{Manage your todo in your terminal}
|
13
|
+
spec.homepage = "https://ompugao.github.io/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "thor"
|
24
|
+
spec.add_dependency "term-ansicolor"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shohei Fujii
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Todo on Terminal
|
70
|
+
email:
|
71
|
+
- fujii.shohei@gmail.com
|
72
|
+
executables:
|
73
|
+
- tot
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/tot
|
83
|
+
- lib/tot.rb
|
84
|
+
- lib/tot/version.rb
|
85
|
+
- tot.gemspec
|
86
|
+
homepage: https://ompugao.github.io/
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Manage your todo in your terminal
|
110
|
+
test_files: []
|