never_do 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb4b077e59b83d0023a6b87f0480fcc61a11901e
4
+ data.tar.gz: 2d3f2a500e61bd13e095f27a8a6298e4a229cd41
5
+ SHA512:
6
+ metadata.gz: 3a74c138d16d9726cd582b84a22eec0e6b3e25d7343a2a3e184ba16c229ecf7cd9d330ff2cd628611eb0af414c0526ebeca9034e3a8cecc4baf1ed3ad3196126
7
+ data.tar.gz: 84ba33b67481cc33fec4dadfc910fb4b51b5f8e43b20ab4505e1692c47008ae398e7dbae16ca5f14e15603f3126f527a56ccf8d67864d4c8efeada3028e14cf3
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in never_do.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # NEVER DO
2
+
3
+ I will do it later usually means I will never do it, if you know what I mean.
4
+
5
+ ## Spirit
6
+
7
+ Once, a little daemon inside my lazy body said to me in my dream:
8
+
9
+ > Neverdo is supposed to be simple, as you will never do it, why make it complex?
10
+ There is no `undo`, `remove`, `clear` or `search` support.
11
+ Make sure you really want to do it, then you can add a task, no `remove`.
12
+ Make sure you have finished one task, then you can `finish` it and never regret.
13
+ If you really want to `clear`, `vim ~/.neverdo/y` and hit `ggdG` should do it just fine.
14
+ If you really want to `search`, `x l | grep ...` should do it just fine.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'never_do'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install never_do
31
+
32
+ ## Usage
33
+
34
+ The executable file is named `x`, todo file is `~/.neverdo/y`, done file is
35
+ `~/.neverdo/z`. The daemon loves math.
36
+
37
+ ```
38
+ x a TASK # add a task
39
+ x l # list all unfinished tasks
40
+ x f ID # finish one task
41
+ x e [yz] # edit [xy]
42
+ x g [PATH] # generate task log, like a summary, in markdown format
43
+ x h # help
44
+ ```
45
+
46
+ Everything after `x` starting with `a` is considered as add a task, thus
47
+ `x a ...` is the same as `x add ...`, the same for `l[ist]`, `f[inish]`,
48
+ `e[dit]`, `g[enerate]`, `h[elp]`.
49
+
50
+ ## Contribute
51
+
52
+ If you find any bug, or have any question, please file an issue or make a pr,
53
+ I will appreciate it very much.
54
+
55
+ ## License
56
+
57
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "never_do"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/x ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "date"
4
+ require "fileutils"
5
+
6
+ PATH = "#{ENV["HOME"]}/.never_do"
7
+ EDITOR = ENV["EDITOR"] || "gvim"
8
+
9
+ class Task
10
+ DELIM = "`"
11
+
12
+ attr_reader :desc, :start, :finish
13
+
14
+ def initialize(desc, start=-1, finish=-1)
15
+ @desc = desc
16
+ @start = start == -1 ? _now : start
17
+ @finish = finish
18
+ end
19
+
20
+ def finish!
21
+ @finish = _now
22
+ self
23
+ end
24
+
25
+ def finish?
26
+ @finish.to_i != -1
27
+ end
28
+
29
+ def to_s
30
+ [@desc, @start, @finish].join(DELIM)
31
+ end
32
+
33
+ class << self
34
+ # backtick ` is the delimiter
35
+ def parse(str)
36
+ Task.new(*str.split(DELIM))
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def _now
43
+ Time.now.to_i
44
+ end
45
+ end
46
+
47
+ class X
48
+ def initialize()
49
+ _ensure_file_structure
50
+ @ys = _load("#{PATH}/y")
51
+ @zs = _load("#{PATH}/z")
52
+ end
53
+
54
+ def add(task)
55
+ @ys << Task.new(task)
56
+ _save
57
+ end
58
+
59
+ def list(done=false)
60
+ len = @ys.size.to_s.length
61
+ @ys.map.with_index { |t, i| "#{i.to_s.ljust(len)} #{t.desc}" }
62
+ end
63
+
64
+ # after finishing one task, the id is renumbered
65
+ def finish(id)
66
+ @zs << @ys.slice!(id).finish!
67
+ _save
68
+ @zs.last
69
+ end
70
+
71
+ def edit(file)
72
+ system "#{EDITOR} #{PATH}/#{file}"
73
+ end
74
+
75
+ def generate(output)
76
+ output ||= "./task_log.md"
77
+ # group by year, then group by month
78
+ File.open(output, "w") do |f|
79
+ [*@ys, *@zs].group_by { |t| Time.at(t.start.to_i).year }.each do |year, y_tasks|
80
+ y_tot = y_tasks.size
81
+ y_done = 0
82
+
83
+ f.puts "## #{year}"
84
+ f.puts "\n------"
85
+ f.puts
86
+
87
+ y_tasks.group_by { |t| Time.at(t.start.to_i).month }.each do |month, m_tasks|
88
+ cur_month = Date::MONTHNAMES[month]
89
+ m_tot = m_tasks.size
90
+ m_done = 0
91
+
92
+ f.puts "### #{cur_month}"
93
+ f.puts "\n------"
94
+ f.puts
95
+
96
+ m_tasks.sort_by(&:start).each do |task|
97
+ mark = task.finish? ? "x" : " "
98
+ done += 1 if task.finish?
99
+ f.puts "- [#{mark}] #{task.desc}"
100
+ end
101
+
102
+ f.puts "\nIn #{cur_month}, you have #{m_tot} tasks, finished #{m_done} tasks, complete #{100.*m_done/m_tot}% of them.\n"
103
+
104
+ y_done += m_done
105
+ end
106
+
107
+ f.puts "\nIn year #{year}, you have #{y_tot} tasks, finished #{y_done} tasks, complete #{100.*y_done/y_tot}% of them.\n"
108
+ end
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def _ensure_file_structure
115
+ Dir.exist?(PATH) || FileUtils.mkdir_p(PATH)
116
+ File.exist?("#{PATH}/y") || FileUtils.touch("#{PATH}/y")
117
+ File.exist?("#{PATH}/z") || FileUtils.touch("#{PATH}/z")
118
+ end
119
+
120
+ def _load(file)
121
+ File.readlines(file).map { |line| Task.parse(line) }
122
+ end
123
+
124
+ def _save
125
+ %w[y z].each do |x|
126
+ File.open("#{PATH}/#{x}", "w") do |f|
127
+ instance_variable_get("@#{x}s").each do |task|
128
+ f.puts task.to_s
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ def help
136
+ puts <<-EOH.gsub(/^\s*\|/, "")
137
+ |Usage: x [OPTION] [ID|TASK|FILE]
138
+ |
139
+ | a TASK add a task
140
+ | l list all tasks
141
+ | f ID finish task with ID
142
+ | e [yz] edit todo file y or done file z
143
+ | g [OUTFILE] generate task log to PATH
144
+ | h see me
145
+ EOH
146
+ end
147
+
148
+ def never_do
149
+ x = X.new
150
+ action = ARGV.shift
151
+ case action
152
+ when /^a.*/
153
+ x.add(ARGV.join(" "))
154
+ when /^l.*/, nil
155
+ x.list.each { |t| puts t }
156
+ when /^f.*/
157
+ task = x.finish(ARGV.first.to_i).desc
158
+ puts "finish task: #{task}"
159
+ when /^e.*/
160
+ file = ARGV.first
161
+ (file == "y" || file == "z") ? x.edit(file) : help
162
+ when /^g.*/
163
+ x.generate(ARGV.first)
164
+ else
165
+ help
166
+ end
167
+ end
168
+
169
+ never_do
170
+
171
+ # vim:ts=4:et
@@ -0,0 +1,3 @@
1
+ module NeverDo
2
+ VERSION = "0.1.1"
3
+ end
data/lib/never_do.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "never_do/version"
2
+
3
+ module NeverDo
4
+ end
data/never_do.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 'never_do/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "never_do"
8
+ spec.version = NeverDo::VERSION
9
+ spec.authors = ["delta"]
10
+ spec.email = ["delta4d@gmail.com"]
11
+
12
+ spec.summary = %q{command line todo app}
13
+ spec.description = %q{a simple command line todo app}
14
+ spec.homepage = "https://github.com/delta4d/never_do"
15
+
16
+ spec.licenses = ["MIT"]
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.executables = ["x"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.4"
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: never_do
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - delta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-04 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: a simple command line todo app
56
+ email:
57
+ - delta4d@gmail.com
58
+ executables:
59
+ - x
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - bin/x
72
+ - lib/never_do.rb
73
+ - lib/never_do/version.rb
74
+ - never_do.gemspec
75
+ homepage: https://github.com/delta4d/never_do
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: command line todo app
99
+ test_files: []