j 0.4.2
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/bin/j +20 -0
- data/how-does-it-work.md +22 -0
- data/j.gemspec +17 -0
- data/lib/j.rb +118 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
j - task manager
|
2
|
+
=================
|
3
|
+
|
4
|
+
j is a simple command-line task manager written in Ruby. Inspired by [t-](http://www.penzba.co.uk/t-/t-.html?HN1) which was written in Python.
|
5
|
+
|
6
|
+
Install:
|
7
|
+
--------
|
8
|
+
|
9
|
+
*This rubygem is yet to be put-up on a distribution channel. But till then enjoy the source*
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
-------
|
13
|
+
|
14
|
+
* List todo tasks
|
15
|
+
j
|
16
|
+
* List all tasks
|
17
|
+
j -a
|
18
|
+
* List done tasks
|
19
|
+
j -d
|
20
|
+
* Mark a task as done
|
21
|
+
j -m <key>
|
22
|
+
* Remove a task
|
23
|
+
j -r <key>
|
24
|
+
* Clear task list
|
25
|
+
j -c
|
26
|
+
|
data/Rakefile
ADDED
data/bin/j
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'rainbow'
|
3
|
+
require File.expand_path('../lib/j', File.dirname(__FILE__))
|
4
|
+
|
5
|
+
|
6
|
+
j = J.new
|
7
|
+
|
8
|
+
if ARGV.count == 0
|
9
|
+
j.listTasks
|
10
|
+
elsif ARGV.count == 1
|
11
|
+
j.listTasks(:done) if ARGV[0] == "-d"
|
12
|
+
j.listTasks(:all) if ARGV[0] == "-a"
|
13
|
+
j.clearList if ARGV[0]=="-c"
|
14
|
+
elsif ARGV.count == 2 and ARGV.first == "-m"
|
15
|
+
j.markTask ARGV[1]
|
16
|
+
elsif ARGV.count == 2 and ARGV.first == "-r"
|
17
|
+
j.deleteTask ARGV[1]
|
18
|
+
else
|
19
|
+
j.addTask ARGV.join(" ")
|
20
|
+
end
|
data/how-does-it-work.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
HowItWorks
|
2
|
+
---------------
|
3
|
+
|
4
|
+
Checks for a .todo file in $HOME
|
5
|
+
if not present create it
|
6
|
+
|
7
|
+
* list (todo) tasks (j)
|
8
|
+
get the contents of the file by line and push to an array
|
9
|
+
and print each todo task in the format: <key> | <status> | <task>
|
10
|
+
Option -a to list all tasks
|
11
|
+
Option -d to list done tasks only
|
12
|
+
|
13
|
+
* create task (j <string>)
|
14
|
+
just append the new task to the file in this format
|
15
|
+
<key> | <status> | <task>
|
16
|
+
|
17
|
+
* Mark as done (j -m <key>)
|
18
|
+
find dump tasks to array, delete that particular task and write back
|
19
|
+
show message. Else show error
|
20
|
+
|
21
|
+
* clear list (j -c)
|
22
|
+
delete the .t.list file
|
data/j.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "j"
|
3
|
+
s.version = "0.4.2"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Akash Manohar"]
|
6
|
+
s.email = ["akash@akash.im"]
|
7
|
+
s.homepage = "http://akash.im"
|
8
|
+
s.summary = "j task manager - v" + s.version.to_s
|
9
|
+
s.description = %q{j, stands for jot and is a simple command-line task manager. Inspired by t- task manager which is written in python}
|
10
|
+
|
11
|
+
s.add_dependency "rainbow", "~> 1.1.1"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
end
|
data/lib/j.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
class J
|
4
|
+
def initialize
|
5
|
+
userHome = Etc.getpwuid.dir
|
6
|
+
@tFilePath = userHome << '/' << ".todo"
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def addTask(task)
|
11
|
+
taskRecord = createTask task
|
12
|
+
writeTaskToFile taskRecord
|
13
|
+
end
|
14
|
+
|
15
|
+
def listTasks(listType=:todo)
|
16
|
+
readTasks
|
17
|
+
if @tasks.count > 0
|
18
|
+
@tasks.each_with_index do |task, i|
|
19
|
+
if ((task[:status] == "DONE" and (listType == :done or listType==:all)) or (task[:status] == "TODO" and (listType == :todo or listType==:all)))
|
20
|
+
puts formatTask(task, i)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
puts "No tasks"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def markTask(key)
|
29
|
+
readTasks
|
30
|
+
key = key.to_i
|
31
|
+
if (key <= @tasks.length)
|
32
|
+
@tasks[key].store(:status, "DONE")
|
33
|
+
puts "DONE".color(:green).bright << " " << @tasks[key][:title]
|
34
|
+
dumpTasksToFile
|
35
|
+
else
|
36
|
+
puts "No such task found!"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def deleteTask(key)
|
41
|
+
readTasks
|
42
|
+
key = key.to_i
|
43
|
+
if key <= @tasks.count
|
44
|
+
task = @tasks[key]
|
45
|
+
@tasks.delete_at(key)
|
46
|
+
if task[:status] == "TODO"
|
47
|
+
puts "Deleted " << task[:status].color(:red).bright << " " << task[:title]
|
48
|
+
else
|
49
|
+
puts "Deleted " << task[:status].color(:green).bright << " " << task[:title]
|
50
|
+
end
|
51
|
+
dumpTasksToFile
|
52
|
+
else
|
53
|
+
puts "No such task found!"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def clearList
|
58
|
+
if File.exists?(@tFilePath)
|
59
|
+
File.delete(@tFilePath)
|
60
|
+
end
|
61
|
+
puts "Cleared list"
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def dumpTasksToFile
|
67
|
+
f = tFile("w+")
|
68
|
+
@tasks.each do |task|
|
69
|
+
taskRecord = task[:status] << " " << task[:title]
|
70
|
+
f << taskRecord
|
71
|
+
end
|
72
|
+
f.close
|
73
|
+
end
|
74
|
+
|
75
|
+
def formatTask(task,key)
|
76
|
+
key = ("[" << key.to_s.foreground(:black).background(:white).bright << "]".background(:white))
|
77
|
+
key = key.background(:white)
|
78
|
+
if task[:status] =="TODO"
|
79
|
+
key << " " << task[:status].foreground(:red).bright << " " << task[:title]
|
80
|
+
else
|
81
|
+
key << " " << task[:status].foreground(:green).bright << " " << task[:title]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def tFile(mode="r+")
|
86
|
+
if File.exists?(@tFilePath)
|
87
|
+
File.open(@tFilePath, mode)
|
88
|
+
else
|
89
|
+
File.new(@tFilePath, "w+")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def createTask(task)
|
94
|
+
"TODO" << " " << task
|
95
|
+
end
|
96
|
+
|
97
|
+
def writeTaskToFile(taskRecord)
|
98
|
+
f = tFile "a+"
|
99
|
+
f << taskRecord << "\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
def readTasks
|
103
|
+
@tasks = []
|
104
|
+
# REcord Pattern: <status:TODO/DONE> <space> <task>
|
105
|
+
taskRecordPattern = /(?<status>\w+)\s(?<title>[\w\s]+)/
|
106
|
+
tFile.readlines.each do |l|
|
107
|
+
if (l.length < 2)
|
108
|
+
next
|
109
|
+
end
|
110
|
+
match = taskRecordPattern.match l
|
111
|
+
task = {
|
112
|
+
:status=> match[:status],
|
113
|
+
:title=> match[:title]
|
114
|
+
}
|
115
|
+
@tasks.push task
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: j
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Akash Manohar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-21 00:00:00 +05:30
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rainbow
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.1.1
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: j, stands for jot and is a simple command-line task manager. Inspired by t- task manager which is written in python
|
28
|
+
email:
|
29
|
+
- akash@akash.im
|
30
|
+
executables:
|
31
|
+
- j
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/j
|
42
|
+
- how-does-it-work.md
|
43
|
+
- j.gemspec
|
44
|
+
- lib/j.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://akash.im
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.5.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: j task manager - v0.4.2
|
73
|
+
test_files: []
|
74
|
+
|