j 0.4.2 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +16 -8
  2. data/bin/j +71 -2
  3. data/j.gemspec +2 -2
  4. data/lib/j.rb +32 -7
  5. metadata +3 -3
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- j - task manager
1
+ j - task manager (v0.5.1)
2
2
  =================
3
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.
4
+ j, stands for jot and is a simple command-line task manager written in Ruby. Inspired by [t-](http://www.penzba.co.uk/t-/t-.html) which was written in Python.
5
5
 
6
6
  Install:
7
7
  --------
8
8
 
9
- *This rubygem is yet to be put-up on a distribution channel. But till then enjoy the source*
9
+ gem install j
10
10
 
11
11
  Usage:
12
12
  -------
@@ -15,12 +15,20 @@ Usage:
15
15
  j
16
16
  * List all tasks
17
17
  j -a
18
- * List done tasks
19
- j -d
18
+ * List finished tasks
19
+ j -f
20
20
  * Mark a task as done
21
21
  j -m <key>
22
- * Remove a task
23
- j -r <key>
24
- * Clear task list
22
+ F.ex: `j -m 3`
23
+ * Delete a task
24
+ j -d <key>
25
+ * Clear task list by deleting the *.todo* file (will be recreated later when needed)
25
26
  j -c
27
+ * Display the scroll to use the magic
28
+ j -h
29
+
30
+ Key is a number that you will find next to a task, when you list tasks. It isn't the same everytime. So watch out!
31
+
32
+ All tasks are stored in the *.todo* file in your *$HOME* directory. However, if your current directory contains a *.todo* file, then that file will be used.
33
+
26
34
 
data/bin/j CHANGED
@@ -1,20 +1,89 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'rainbow'
3
+ require 'optparse'
3
4
  require File.expand_path('../lib/j', File.dirname(__FILE__))
4
5
 
5
6
 
6
7
  j = J.new
7
8
 
9
+ validOptions = ["-a", "--all",
10
+ "-f", "--finished",
11
+ "-t", "--todo",
12
+ "-m", "--mark",
13
+ "-d", "--delete",
14
+ "-c", "--clear",
15
+ "-h", "--help"]
16
+
17
+ if ARGV.length > 0 and validOptions.include?(ARGV.first)
18
+
19
+ options = OptionParser.new do |o|
20
+ o.banner = "j task manager"
21
+
22
+ o.on('-a', "--all", "List all tasks") do |b|
23
+ j.listTasks(:all)
24
+ exit
25
+ end
26
+
27
+ o.on('-t', "--todo", "List todo. Same as using command without options") do |b|
28
+ j.listTasks(:todo)
29
+ exit
30
+ end
31
+
32
+ o.on('-f', "--finished", "List finished tasks") do |b|
33
+ j.listTasks(:done)
34
+ exit
35
+ end
36
+
37
+ o.on('-m KEY', "--mark KEY", "Mark a task a completed") do |key|
38
+ if j.validKey key
39
+ j.markTask key
40
+ else
41
+ puts o
42
+ end
43
+ exit
44
+ end
45
+
46
+ o.on('-d KEY', "--delete KEY", "Delete a task") do |key|
47
+ if j.validKey key
48
+ j.deleteTask key
49
+ else
50
+ puts o
51
+ end
52
+ exit
53
+ end
54
+
55
+ o.on('-c', "--clear", "Clears the todo list") do |b|
56
+ j.clearList
57
+ exit
58
+ end
59
+
60
+ o.on('-h', "--help", "Displays this message") do |b|
61
+ puts o
62
+ exit
63
+ end
64
+
65
+ end
66
+
67
+ options.parse!
68
+
69
+ elsif ARGV.length > 0
70
+ j.addTask ARGV.join(" ")
71
+ elsif ARGV.length == 0
72
+ j.listTasks(:todo)
73
+ end
74
+
75
+ =begin
8
76
  if ARGV.count == 0
9
77
  j.listTasks
10
78
  elsif ARGV.count == 1
11
- j.listTasks(:done) if ARGV[0] == "-d"
79
+ j.listTasks(:done) if ARGV[0] == "-f"
12
80
  j.listTasks(:all) if ARGV[0] == "-a"
13
81
  j.clearList if ARGV[0]=="-c"
14
82
  elsif ARGV.count == 2 and ARGV.first == "-m"
15
83
  j.markTask ARGV[1]
16
- elsif ARGV.count == 2 and ARGV.first == "-r"
84
+ elsif ARGV.count == 2 and ARGV.first == "-d"
17
85
  j.deleteTask ARGV[1]
18
86
  else
19
87
  j.addTask ARGV.join(" ")
20
88
  end
89
+ =end
data/j.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "j"
3
- s.version = "0.4.2"
3
+ s.version = "0.5.1"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Akash Manohar"]
6
6
  s.email = ["akash@akash.im"]
7
- s.homepage = "http://akash.im"
7
+ s.homepage = "http://akash.im/j"
8
8
  s.summary = "j task manager - v" + s.version.to_s
9
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
10
 
data/lib/j.rb CHANGED
@@ -3,12 +3,22 @@ require 'etc'
3
3
  class J
4
4
  def initialize
5
5
  userHome = Etc.getpwuid.dir
6
- @tFilePath = userHome << '/' << ".todo"
7
-
6
+ if File.exists?(Dir.pwd << "/.todo")
7
+ @tFilePath = Dir.pwd << "/.todo"
8
+ if (Dir.pwd == userHome)
9
+ @globalTodo = true
10
+ else
11
+ @globalTodo = false
12
+ end
13
+ else
14
+ @globalTodo = true
15
+ @tFilePath = userHome << '/' << ".todo"
16
+ end
8
17
  end
9
18
 
10
19
  def addTask(task)
11
20
  taskRecord = createTask task
21
+ puts "*NEW* " << "TODO".foreground(:red).bright << " " << task
12
22
  writeTaskToFile taskRecord
13
23
  end
14
24
 
@@ -21,7 +31,11 @@ class J
21
31
  end
22
32
  end
23
33
  else
24
- puts "No tasks"
34
+ if @globalTodo
35
+ puts "No tasks!"
36
+ else
37
+ puts "No tasks in project todo list. To delete project todo list use option -c"
38
+ end
25
39
  end
26
40
  end
27
41
 
@@ -58,15 +72,23 @@ class J
58
72
  if File.exists?(@tFilePath)
59
73
  File.delete(@tFilePath)
60
74
  end
61
- puts "Cleared list"
75
+ if @globalTodo
76
+ puts "Cleared todo list"
77
+ else
78
+ puts "Cleared project todo list"
79
+ end
62
80
  end
81
+
82
+ def validKey(key)
83
+ return true unless key.match(/\A[0-9]+\Z/).nil?
84
+ end
63
85
 
64
86
  private
65
87
 
66
88
  def dumpTasksToFile
67
89
  f = tFile("w+")
68
90
  @tasks.each do |task|
69
- taskRecord = task[:status] << " " << task[:title]
91
+ taskRecord = task[:status] << " " << task[:title] << "\n"
70
92
  f << taskRecord
71
93
  end
72
94
  f.close
@@ -100,9 +122,12 @@ class J
100
122
  end
101
123
 
102
124
  def readTasks
125
+
103
126
  @tasks = []
104
- # REcord Pattern: <status:TODO/DONE> <space> <task>
105
- taskRecordPattern = /(?<status>\w+)\s(?<title>[\w\s]+)/
127
+
128
+ # Record Pattern: <status:TODO/DONE> <space> <task>
129
+ taskRecordPattern = /(?<status>(TODO|DONE))\s(?<title>.+)\Z/
130
+
106
131
  tFile.readlines.each do |l|
107
132
  if (l.length < 2)
108
133
  next
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: j
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.2
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Akash Manohar
@@ -43,7 +43,7 @@ files:
43
43
  - j.gemspec
44
44
  - lib/j.rb
45
45
  has_rdoc: true
46
- homepage: http://akash.im
46
+ homepage: http://akash.im/j
47
47
  licenses: []
48
48
 
49
49
  post_install_message:
@@ -69,6 +69,6 @@ rubyforge_project:
69
69
  rubygems_version: 1.5.0
70
70
  signing_key:
71
71
  specification_version: 3
72
- summary: j task manager - v0.4.2
72
+ summary: j task manager - v0.5.1
73
73
  test_files: []
74
74