swatch 0.3 → 0.3.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.
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +6 -1
- data/bin/swatch +6 -5
- data/lib/swatch.rb +114 -104
- metadata +6 -6
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
|
@@ -16,6 +16,9 @@ Getting out:
|
|
|
16
16
|
Timing a todo.txt task:
|
|
17
17
|
swatch in -t 42
|
|
18
18
|
|
|
19
|
+
What am I currently tracking:
|
|
20
|
+
swatch what
|
|
21
|
+
|
|
19
22
|
== Config
|
|
20
23
|
|
|
21
24
|
Swatch look for the ~/.swatchrc file. If it's present swatch will parse it to get track_file and todo_file path.
|
|
@@ -26,4 +29,6 @@ Exemple :
|
|
|
26
29
|
By default (i.e if there is no ~/.swatchrc file), swatch will look for todo file in ~/.todo.txt and track_file in ~/.swatch.txt.
|
|
27
30
|
|
|
28
31
|
== Todo
|
|
29
|
-
*
|
|
32
|
+
* Implement report functionnality
|
|
33
|
+
* Add option to only print duration of the "what" command
|
|
34
|
+
* Add option to start/end task at a certain time
|
data/bin/swatch
CHANGED
|
@@ -19,7 +19,7 @@ require_relative '../lib/swatch'
|
|
|
19
19
|
# ###############
|
|
20
20
|
|
|
21
21
|
CONF_FILE = File.expand_path("~/.swatchrc")
|
|
22
|
-
VERSION = '0.3'
|
|
22
|
+
VERSION = '0.3.1'
|
|
23
23
|
|
|
24
24
|
if File.exist? CONF_FILE
|
|
25
25
|
config = ParseConfig.new(CONF_FILE)
|
|
@@ -61,8 +61,8 @@ cmd_opts = case cmd
|
|
|
61
61
|
opt :todo, "Track a todo.txt task", :type => :int, :short => "-t"
|
|
62
62
|
end
|
|
63
63
|
when "out", "o"
|
|
64
|
-
when "what"
|
|
65
|
-
when "report"
|
|
64
|
+
when "what", "w"
|
|
65
|
+
when "report", "r"
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
#puts "Global options: #{global_opts.inspect}"
|
|
@@ -81,6 +81,7 @@ when "in", "i"
|
|
|
81
81
|
end
|
|
82
82
|
when "out", "o"
|
|
83
83
|
Swatch::task_out
|
|
84
|
-
when "what"
|
|
85
|
-
|
|
84
|
+
when "what", "w"
|
|
85
|
+
Swatch::what_task
|
|
86
|
+
when "report", "r"
|
|
86
87
|
end
|
data/lib/swatch.rb
CHANGED
|
@@ -11,109 +11,119 @@ require_relative './numeric.rb'
|
|
|
11
11
|
|
|
12
12
|
module Swatch
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
# Test if there is a task currently running. Return true if there is
|
|
17
|
+
def running_task?
|
|
18
|
+
line = ''
|
|
19
|
+
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
|
20
|
+
#puts line
|
|
21
|
+
if(line != nil && (!line.match '^.+\t\d+\t\d+$'))
|
|
22
|
+
true
|
|
23
|
+
else
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Return the start time of a running task
|
|
29
|
+
def get_last_task_stime
|
|
30
|
+
line = ''
|
|
31
|
+
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
|
32
|
+
if line == nil
|
|
33
|
+
return false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
line.split("\t").pop
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Return the name of the last task
|
|
40
|
+
def get_last_task_name
|
|
41
|
+
line = ''
|
|
42
|
+
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
|
43
|
+
if line == nil
|
|
44
|
+
return false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
line = line.split "\t"
|
|
48
|
+
if running_task?
|
|
49
|
+
line.pop
|
|
50
|
+
else
|
|
51
|
+
line.pop 2
|
|
52
|
+
end
|
|
53
|
+
line.join "\t"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Go out of the current task running
|
|
57
|
+
def task_out
|
|
58
|
+
if running_task?
|
|
59
|
+
puts "Stop task: " + get_last_task_name + ", #{(Time.now.to_i - get_last_task_stime.to_i).duration}"
|
|
60
|
+
open(TRACK_FILE, "a"){|f|
|
|
61
|
+
f.print "\t#{Time.now.to_i}\n"
|
|
62
|
+
}
|
|
63
|
+
return true
|
|
64
|
+
else
|
|
65
|
+
puts "There is no task running"
|
|
66
|
+
return false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Start a task
|
|
71
|
+
def task_in (task)
|
|
72
|
+
# don't go here if ARGV is null !
|
|
73
|
+
if task.strip.empty?
|
|
74
|
+
puts "No task specified"
|
|
75
|
+
return false
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# if there is a task running, we get out of it
|
|
79
|
+
if running_task?
|
|
80
|
+
#puts "There is a task running, getting out of this one"
|
|
81
|
+
task_out
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if(!File.exist?(TRACK_FILE))
|
|
85
|
+
#puts "Create a new task file"
|
|
86
|
+
out = File.new(TRACK_FILE, "w")
|
|
87
|
+
else
|
|
88
|
+
#puts "Use #{TRACK_FILE}"
|
|
89
|
+
out = File.open(TRACK_FILE, "a")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#print the task in the file
|
|
93
|
+
out.print "#{task}\t#{Time.now.to_i}"
|
|
94
|
+
out.close
|
|
95
|
+
|
|
96
|
+
puts "Start task: #{task}"
|
|
63
97
|
return true
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
puts "Start task: #{task}"
|
|
97
|
-
return true
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Return the todo associated to the given number
|
|
101
|
-
def get_todo (nb)
|
|
102
|
-
# TODO: parse todo to remove the priority
|
|
103
|
-
line = IO.readlines(TODO_FILE)[nb-1]
|
|
104
|
-
if line.match '^\(([A-Z])\)'
|
|
105
|
-
line.slice!(0..4)
|
|
106
|
-
end
|
|
107
|
-
line
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Going in a task with a todo from todo.txt
|
|
111
|
-
def task_in_todo (nb)
|
|
112
|
-
t = get_todo (nb)
|
|
113
|
-
if t
|
|
114
|
-
task_in t.chomp
|
|
115
|
-
else
|
|
116
|
-
puts "No task specified"
|
|
117
|
-
end
|
|
118
|
-
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Return the todo associated to the given number
|
|
101
|
+
def get_todo (nb)
|
|
102
|
+
# TODO: parse todo to remove the priority
|
|
103
|
+
line = IO.readlines(TODO_FILE)[nb-1]
|
|
104
|
+
if line.match '^\(([A-Z])\)'
|
|
105
|
+
line.slice!(0..4)
|
|
106
|
+
end
|
|
107
|
+
line
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Going in a task with a todo from todo.txt
|
|
111
|
+
def task_in_todo (nb)
|
|
112
|
+
t = get_todo (nb)
|
|
113
|
+
if t
|
|
114
|
+
task_in t.chomp
|
|
115
|
+
else
|
|
116
|
+
puts "No task specified"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# What task are currently running
|
|
121
|
+
def what_task
|
|
122
|
+
if running_task?
|
|
123
|
+
puts "Current task: " + get_last_task_name + ", #{(Time.now.to_i - get_last_task_stime.to_i).duration}"
|
|
124
|
+
else
|
|
125
|
+
puts "No task running!"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
119
129
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,12 +9,12 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2011-03-
|
|
12
|
+
date: 2011-03-07 00:00:00.000000000 +01:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: trollop
|
|
17
|
-
requirement: &
|
|
17
|
+
requirement: &12461520 !ruby/object:Gem::Requirement
|
|
18
18
|
none: false
|
|
19
19
|
requirements:
|
|
20
20
|
- - ! '>='
|
|
@@ -22,10 +22,10 @@ dependencies:
|
|
|
22
22
|
version: '0'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
|
-
version_requirements: *
|
|
25
|
+
version_requirements: *12461520
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: parseconfig
|
|
28
|
-
requirement: &
|
|
28
|
+
requirement: &12461080 !ruby/object:Gem::Requirement
|
|
29
29
|
none: false
|
|
30
30
|
requirements:
|
|
31
31
|
- - ! '>='
|
|
@@ -33,7 +33,7 @@ dependencies:
|
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
|
-
version_requirements: *
|
|
36
|
+
version_requirements: *12461080
|
|
37
37
|
description: ! 'Swatch is a simple timetracking script in Ruby.
|
|
38
38
|
|
|
39
39
|
It can be used in conjonction of the todo.txt script
|