swatch 0.2.2 → 0.3
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 +20 -0
- data/LICENSE +8 -0
- data/README.rdoc +29 -0
- data/bin/swatch +4 -5
- data/lib/numeric.rb +26 -0
- data/lib/swatch.rb +37 -8
- metadata +49 -47
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= Changelog
|
2
|
+
|
3
|
+
== 0.3
|
4
|
+
* Add test for the library
|
5
|
+
* Add the elapsed time when you go out a task
|
6
|
+
* Remove the priority of todo.txt in the .swatch.txt file
|
7
|
+
* Clean some comment
|
8
|
+
* Correct bug discovered by the newly created test
|
9
|
+
|
10
|
+
== 0.2.2
|
11
|
+
Minor update to add dependencies to Trollop and parseconfig
|
12
|
+
|
13
|
+
== 0.2.1
|
14
|
+
Minor update to add config file support
|
15
|
+
|
16
|
+
== 0.2
|
17
|
+
Add a simple support of todo.txt
|
18
|
+
|
19
|
+
== 0.1
|
20
|
+
First usable version, with no support of todo.txt
|
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
------------------------------------------------------------------------------
|
2
|
+
"THE BEER-WARE LICENSE" (Revision 42):
|
3
|
+
<mayeu.tik@gmail.com> wrote this gem. As long as you retain this notice you
|
4
|
+
can do whatever you want with this stuff. If we meet some day, and you think
|
5
|
+
this stuff is worth it, you can buy me a beer in return. Matthieu Maury
|
6
|
+
------------------------------------------------------------------------------
|
7
|
+
|
8
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= Swatch
|
2
|
+
|
3
|
+
A simple command line utility in Ruby to track your time.
|
4
|
+
Can be use with todo.txt task list.
|
5
|
+
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
swatch command [option] arg
|
9
|
+
|
10
|
+
Going in a task :
|
11
|
+
swatch in My awesome task
|
12
|
+
|
13
|
+
Getting out:
|
14
|
+
swatch out
|
15
|
+
|
16
|
+
Timing a todo.txt task:
|
17
|
+
swatch in -t 42
|
18
|
+
|
19
|
+
== Config
|
20
|
+
|
21
|
+
Swatch look for the ~/.swatchrc file. If it's present swatch will parse it to get track_file and todo_file path.
|
22
|
+
Exemple :
|
23
|
+
track_file = "~/todo/swatchtrack.txt"
|
24
|
+
todo_file = "~/todo/todo.txt"
|
25
|
+
|
26
|
+
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
|
+
|
28
|
+
== Todo
|
29
|
+
* parse todo to remove the priority
|
data/bin/swatch
CHANGED
@@ -10,15 +10,16 @@
|
|
10
10
|
#
|
11
11
|
|
12
12
|
require 'trollop'
|
13
|
-
require '
|
14
|
-
|
13
|
+
require 'parseconfig'
|
14
|
+
|
15
|
+
require_relative '../lib/swatch'
|
15
16
|
|
16
17
|
# ###############
|
17
18
|
# Global variable
|
18
19
|
# ###############
|
19
20
|
|
20
21
|
CONF_FILE = File.expand_path("~/.swatchrc")
|
21
|
-
VERSION = '0.
|
22
|
+
VERSION = '0.3'
|
22
23
|
|
23
24
|
if File.exist? CONF_FILE
|
24
25
|
config = ParseConfig.new(CONF_FILE)
|
@@ -83,5 +84,3 @@ when "out", "o"
|
|
83
84
|
when "what" || "w"
|
84
85
|
when "report" || "r"
|
85
86
|
end
|
86
|
-
|
87
|
-
|
data/lib/numeric.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Extend the numeric class with the "duration" method that print a
|
3
|
+
# duration in human langage.
|
4
|
+
# This code was found at:
|
5
|
+
# http://stackoverflow.com/questions/1679266/can-ruby-print-out-time-difference-duration-readily
|
6
|
+
#
|
7
|
+
|
8
|
+
class Numeric
|
9
|
+
def duration
|
10
|
+
secs = self.to_int
|
11
|
+
mins = secs / 60
|
12
|
+
hours = mins / 60
|
13
|
+
days = hours / 24
|
14
|
+
|
15
|
+
if days > 0
|
16
|
+
"#{days} days and #{hours % 24} hours"
|
17
|
+
elsif hours > 0
|
18
|
+
"#{hours} hours and #{mins % 60} minutes"
|
19
|
+
elsif mins > 0
|
20
|
+
"#{mins} minutes and #{secs % 60} seconds"
|
21
|
+
elsif secs >= 0
|
22
|
+
"#{secs} seconds"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/swatch.rb
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
#------------------------------------------------------------------------------
|
8
8
|
#
|
9
9
|
|
10
|
+
require_relative './numeric.rb'
|
11
|
+
|
10
12
|
module Swatch
|
11
13
|
|
12
14
|
module_function
|
@@ -23,23 +25,45 @@ module Swatch
|
|
23
25
|
end
|
24
26
|
end
|
25
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
|
+
|
26
39
|
# Return the name of the last task
|
27
40
|
def get_last_task_name
|
28
41
|
line = ''
|
29
42
|
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
30
|
-
|
31
|
-
|
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"
|
32
54
|
end
|
33
55
|
|
34
56
|
# Go out of the current task running
|
35
57
|
def task_out
|
36
58
|
if running_task?
|
37
|
-
puts "Stop task: " + get_last_task_name
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
64
|
else
|
42
65
|
puts "There is no task running"
|
66
|
+
return false
|
43
67
|
end
|
44
68
|
end
|
45
69
|
|
@@ -48,7 +72,7 @@ module Swatch
|
|
48
72
|
# don't go here if ARGV is null !
|
49
73
|
if task.strip.empty?
|
50
74
|
puts "No task specified"
|
51
|
-
|
75
|
+
return false
|
52
76
|
end
|
53
77
|
|
54
78
|
# if there is a task running, we get out of it
|
@@ -70,12 +94,17 @@ module Swatch
|
|
70
94
|
out.close
|
71
95
|
|
72
96
|
puts "Start task: #{task}"
|
97
|
+
return true
|
73
98
|
end
|
74
99
|
|
75
100
|
# Return the todo associated to the given number
|
76
101
|
def get_todo (nb)
|
77
102
|
# TODO: parse todo to remove the priority
|
78
|
-
IO.readlines(TODO_FILE)[nb-1]
|
103
|
+
line = IO.readlines(TODO_FILE)[nb-1]
|
104
|
+
if line.match '^\(([A-Z])\)'
|
105
|
+
line.slice!(0..4)
|
106
|
+
end
|
107
|
+
line
|
79
108
|
end
|
80
109
|
|
81
110
|
# Going in a task with a todo from todo.txt
|
metadata
CHANGED
@@ -1,77 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: swatch
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.3'
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Matthieu Maury
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2011-01-24 00:00:00 +01:00
|
12
|
+
date: 2011-03-03 00:00:00.000000000 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
16
|
name: trollop
|
17
|
+
requirement: &13186500 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
17
23
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements:
|
20
|
-
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *13186500
|
26
|
+
- !ruby/object:Gem::Dependency
|
26
27
|
name: parseconfig
|
28
|
+
requirement: &13186060 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
27
34
|
type: :runtime
|
28
|
-
|
29
|
-
version_requirements:
|
30
|
-
|
31
|
-
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
|
-
description: |
|
36
|
-
Swatch is a simple timetracking script in Ruby.
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *13186060
|
37
|
+
description: ! 'Swatch is a simple timetracking script in Ruby.
|
38
|
+
|
37
39
|
It can be used in conjonction of the todo.txt script
|
38
40
|
|
41
|
+
'
|
39
42
|
email: mayeu.tik@gmail.com
|
40
|
-
executables:
|
43
|
+
executables:
|
41
44
|
- swatch
|
42
45
|
extensions: []
|
43
|
-
|
44
46
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
47
|
+
files:
|
47
48
|
- lib/swatch.rb
|
49
|
+
- lib/numeric.rb
|
50
|
+
- README.rdoc
|
51
|
+
- CHANGELOG.rdoc
|
52
|
+
- LICENSE
|
53
|
+
- bin/swatch
|
48
54
|
has_rdoc: true
|
49
55
|
homepage: http://github.com/Mayeutik/swatch
|
50
56
|
licenses: []
|
51
|
-
|
52
57
|
post_install_message:
|
53
58
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
59
|
+
require_paths:
|
56
60
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
69
73
|
requirements: []
|
70
|
-
|
71
74
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.6.0
|
73
76
|
signing_key:
|
74
77
|
specification_version: 3
|
75
78
|
summary: A simple cli timetracking script that can be use with todo.txt
|
76
79
|
test_files: []
|
77
|
-
|