swatch 0.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/CHANGELOG.rdoc +0 -0
- data/LICENSE +8 -0
- data/README.rdoc +4 -0
- data/bin/swatch +80 -0
- data/lib/swatch.rb +80 -0
- metadata +70 -0
data/CHANGELOG.rdoc
ADDED
File without changes
|
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
data/bin/swatch
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
#------------------------------------------------------------------------------
|
5
|
+
# "THE BEER-WARE LICENSE" (Revision 42):
|
6
|
+
# <mayeu.tik@gmail.com> wrote this file. As long as you retain this notice you
|
7
|
+
# can do whatever you want with this stuff. If we meet some day, and you think
|
8
|
+
# this stuff is worth it, you can buy me a beer in return. Matthieu Maury
|
9
|
+
#------------------------------------------------------------------------------
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'trollop'
|
13
|
+
require 'swatch'
|
14
|
+
|
15
|
+
# ###############
|
16
|
+
# Global variable
|
17
|
+
# ###############
|
18
|
+
|
19
|
+
CONF_FILE = File.expand_path("~/.swatchrc")
|
20
|
+
TRACK_FILE = File.expand_path("~/todo/swatchtrack.txt")
|
21
|
+
TODO_FILE = File.expand_path("~/todo/todo.txt")
|
22
|
+
VERSION = 0.2
|
23
|
+
|
24
|
+
# #####################
|
25
|
+
# Subcommand definition
|
26
|
+
# #####################
|
27
|
+
|
28
|
+
SUB_COMMANDS = %w(in i out o what w report r)
|
29
|
+
global_opts = Trollop::options do
|
30
|
+
version VERSION
|
31
|
+
banner <<-EOS
|
32
|
+
Swatch, a command line utility to track the time you spend.
|
33
|
+
swatch [-hv] <command> <command options> <command arg>
|
34
|
+
|
35
|
+
You can have detailled instruction on a command with:
|
36
|
+
swatch -h <command>
|
37
|
+
|
38
|
+
in, i: launch the time tracker
|
39
|
+
swatch in "task"
|
40
|
+
out, o: stop the current running task
|
41
|
+
swatch out
|
42
|
+
what, w: print the current task on stdout
|
43
|
+
swatch what
|
44
|
+
EOS
|
45
|
+
stop_on SUB_COMMANDS
|
46
|
+
end
|
47
|
+
|
48
|
+
cmd = ARGV.shift # get the subcommand
|
49
|
+
cmd_opts = case cmd
|
50
|
+
when "in", "i"
|
51
|
+
# TODO add todo.txt support
|
52
|
+
Trollop::options do
|
53
|
+
opt :todo, "Track a todo.txt task", :type => :int, :short => "-t"
|
54
|
+
end
|
55
|
+
when "out", "o"
|
56
|
+
when "what" || "w"
|
57
|
+
when "report" || "r"
|
58
|
+
end
|
59
|
+
|
60
|
+
#puts "Global options: #{global_opts.inspect}"
|
61
|
+
#puts "Subcommand: #{cmd.inspect}"
|
62
|
+
#puts "Subcommand options: #{cmd_opts.inspect}"
|
63
|
+
#puts "Remaining arguments: #{ARGV.inspect}"
|
64
|
+
|
65
|
+
# Now we have the arg. So, what do we do ?
|
66
|
+
|
67
|
+
case cmd
|
68
|
+
when "in", "i"
|
69
|
+
unless cmd_opts[:todo]
|
70
|
+
Swatch::task_in ARGV.join(" ").chomp
|
71
|
+
else
|
72
|
+
Swatch::task_in_todo cmd_opts[:todo]
|
73
|
+
end
|
74
|
+
when "out", "o"
|
75
|
+
Swatch::task_out
|
76
|
+
when "what" || "w"
|
77
|
+
when "report" || "r"
|
78
|
+
end
|
79
|
+
|
80
|
+
|
data/lib/swatch.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Swatch
|
2
|
+
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Test if there is a task currently running. Return true if there is
|
6
|
+
def running_task?
|
7
|
+
line = ''
|
8
|
+
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
9
|
+
#puts line
|
10
|
+
if(line != nil && (!line.match '^.+\t\d+\t\d+$'))
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return the name of the last task
|
18
|
+
def get_last_task_name
|
19
|
+
line = ''
|
20
|
+
IO.popen("tail -n 1 #{TRACK_FILE}") { |f| line = f.gets }
|
21
|
+
m = line.match '^(.+)\t\d+(\t\d+)?'
|
22
|
+
m[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Go out of the current task running
|
26
|
+
def task_out
|
27
|
+
if running_task?
|
28
|
+
puts "Stop task: " + get_last_task_name
|
29
|
+
f = File.open(TRACK_FILE, "a")
|
30
|
+
f.print "\t#{Time.now.to_i}\n"
|
31
|
+
f.close
|
32
|
+
else
|
33
|
+
puts "There is no task running"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Start a task
|
38
|
+
def task_in (task)
|
39
|
+
# don't go here if ARGV is null !
|
40
|
+
if task.strip.empty?
|
41
|
+
puts "No task specified"
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
# if there is a task running, we get out of it
|
46
|
+
if running_task?
|
47
|
+
#puts "There is a task running, getting out of this one"
|
48
|
+
task_out
|
49
|
+
end
|
50
|
+
|
51
|
+
if(!File.exist?(TRACK_FILE))
|
52
|
+
#puts "Create a new task file"
|
53
|
+
out = File.new(TRACK_FILE, "w")
|
54
|
+
else
|
55
|
+
#puts "Use #{TRACK_FILE}"
|
56
|
+
out = File.open(TRACK_FILE, "a")
|
57
|
+
end
|
58
|
+
|
59
|
+
#print the task in the file
|
60
|
+
out.print "#{task}\t#{Time.now.to_i}"
|
61
|
+
out.close
|
62
|
+
|
63
|
+
puts "Start task: #{task}"
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return the todo associated to the given number
|
67
|
+
def get_todo (nb)
|
68
|
+
IO.readlines(TODO_FILE)[nb-1]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Going in a task with a todo from todo.txt
|
72
|
+
def task_in_todo (nb)
|
73
|
+
t = get_todo (nb)
|
74
|
+
if t
|
75
|
+
task_in t.chomp
|
76
|
+
else
|
77
|
+
puts "No task specified"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Matthieu Maury
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-12-24 00:00:00 +01:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: |
|
21
|
+
Swatch is a simple timetracking script in Ruby.
|
22
|
+
It can be used in conjonction of the todo.txt script
|
23
|
+
|
24
|
+
email: mayeu.tik@gmail.com
|
25
|
+
executables:
|
26
|
+
- swatch
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- lib/swatch.rb
|
33
|
+
- README.rdoc
|
34
|
+
- CHANGELOG.rdoc
|
35
|
+
- LICENSE
|
36
|
+
- bin/swatch
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/Mayeutik/swatch
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A simple cli timetracking script that can be use with todo.txt
|
69
|
+
test_files: []
|
70
|
+
|