routinized 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -3
- data/bin/routinized +9 -2
- data/lib/commands/rss.rb +18 -0
- data/lib/routinized.rb +19 -6
- data/lib/routinized/version.rb +1 -1
- data/lib/templates/master.rb.template +3 -5
- data/lib/{commands → wrappers}/itunes_play.rb +0 -0
- data/lib/wrappers/osx_notify.rb +8 -0
- data/lib/wrappers/pipe.rb +3 -0
- data/lib/wrappers/r.rb +3 -0
- data/lib/wrappers/say.rb +8 -0
- data/lib/{commands → wrappers}/sleep.rb +0 -0
- data/lib/wrappers/top.rb +3 -0
- metadata +10 -6
- data/lib/commands/osx_notify.rb +0 -4
- data/lib/commands/say.rb +0 -4
data/README.md
CHANGED
@@ -37,8 +37,9 @@ Once installed, it's time to make your dotfiles...everything lives in
|
|
37
37
|
This makes all sorts of files for you:
|
38
38
|
|
39
39
|
~/.routinized/master.rb # your master routine
|
40
|
-
~/.routinized/config.json # location of binaries
|
41
|
-
~/.routinized/
|
40
|
+
~/.routinized/config.json # location of binaries wrappers might need
|
41
|
+
~/.routinized/wrappers/* # wrappers around binaries to make cron entries
|
42
|
+
~/.routinized/commands/* # Ruby scripts executed from cron itself
|
42
43
|
|
43
44
|
After you've made all sorts of changes, you can generate and install the
|
44
45
|
crontab via:
|
@@ -52,6 +53,23 @@ is as easy as:
|
|
52
53
|
|
53
54
|
(depending on the command, you might need to customize config.json)
|
54
55
|
|
56
|
+
## Wrappers and Commands
|
57
|
+
|
58
|
+
In short, wrappers are Ruby transformations that turn into a command line
|
59
|
+
that lives in the crontab.
|
60
|
+
|
61
|
+
Commands are executed from the command line and execute Ruby code.
|
62
|
+
|
63
|
+
So a wrapper is executed when building the crontab, a command is executed
|
64
|
+
every time the cron entry runs.
|
65
|
+
|
66
|
+
The 'pipe' wrapper makes use of [Parallel](http://www.gnu.org/software/parallel/)
|
67
|
+
which can be installed via:
|
68
|
+
|
69
|
+
$ brew install parallel
|
70
|
+
|
71
|
+
It's basically a smarter xargs.
|
72
|
+
|
55
73
|
## Routine
|
56
74
|
|
57
75
|
Since this is a layer on top of whenever, you can do things like:
|
@@ -72,7 +90,6 @@ end
|
|
72
90
|
|
73
91
|
# Stretch Break every 30 minutes during the work week
|
74
92
|
every '*/30 9-16 * * 1-5' do
|
75
|
-
command sleep(5) + say('Time to stretch')
|
76
93
|
command osx_notify('Stretch',"Take a short break and stretch")
|
77
94
|
end
|
78
95
|
|
data/bin/routinized
CHANGED
@@ -10,7 +10,8 @@ opt_parser = OptionParser.new do |opt|
|
|
10
10
|
opt.separator "Commands"
|
11
11
|
opt.separator " bootstrap - seeds your .routinized/* dotfiles"
|
12
12
|
opt.separator " install - current routine is installed in cron"
|
13
|
-
opt.separator " upgrade - grabs new commands
|
13
|
+
opt.separator " upgrade - grabs new commands and wrappers"
|
14
|
+
opt.separator " command (args) - executes a custom command"
|
14
15
|
opt.separator ""
|
15
16
|
|
16
17
|
opt.on("-h","--help","help") do
|
@@ -23,6 +24,12 @@ opt_parser.parse!
|
|
23
24
|
$stdout.sync = true
|
24
25
|
|
25
26
|
case ARGV[0]
|
27
|
+
when "command"
|
28
|
+
command = ARGV[0]
|
29
|
+
name = ARGV[1]
|
30
|
+
args = ARGV.drop(2)
|
31
|
+
#puts "Running #{name} with #{args}"
|
32
|
+
Routinized.command(name,args)
|
26
33
|
when "bootstrap"
|
27
34
|
puts "Populating ~/.routinized..."
|
28
35
|
Routinized.bootstrap
|
@@ -34,7 +41,7 @@ when "install"
|
|
34
41
|
puts " sudo launchctl unload /System/Library/LaunchDaemons/com.vix.cron.plist"
|
35
42
|
puts " sudo launchctl load /System/Library/LaunchDaemons/com.vix.cron.plist"
|
36
43
|
when "upgrade"
|
37
|
-
puts "Upgrading available commands..."
|
44
|
+
puts "Upgrading available commands and wrappers..."
|
38
45
|
Routinized.upgrade.each{|x| puts " #{x}"}
|
39
46
|
puts "Done! Be sure to run 'gem install routinized' to get the latest."
|
40
47
|
else
|
data/lib/commands/rss.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rss'
|
2
|
+
require 'open-uri'
|
3
|
+
module Routinized
|
4
|
+
module Commands
|
5
|
+
def self.rss(args)
|
6
|
+
feed_url = args.first
|
7
|
+
result = ""
|
8
|
+
open(feed_url) do |rss|
|
9
|
+
feed = RSS::Parser.parse(rss)
|
10
|
+
#result += "Title: #{feed.channel.title}\n"
|
11
|
+
feed.items.each do |item|
|
12
|
+
result += "Item: #{item.title}\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/routinized.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "routinized/version"
|
2
2
|
require 'fileutils'
|
3
3
|
require 'json'
|
4
|
+
Dir[File.dirname(__FILE__) + '/commands/*.rb'].each {|file| require file }
|
4
5
|
module Routinized
|
5
6
|
ROOT = File.join(Dir.home,'.routinized')
|
6
7
|
|
@@ -9,16 +10,28 @@ module Routinized
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.upgrade
|
12
|
-
|
13
|
-
Dir.mkdir("commands") unless File.exists?("commands")
|
14
|
-
FileUtils.cp_r Dir.glob(File.dirname(__FILE__) + '/commands/*.rb'), File.join(ROOT,'commands')
|
15
|
-
return Dir.entries(File.join(ROOT,'commands')).select{|f| f =~ /rb/}.map{|x| x.split(".rb").first}
|
13
|
+
_distribute_files('wrappers') + _distribute_files('commands')
|
16
14
|
end
|
17
15
|
|
18
16
|
def self.bootstrap
|
19
17
|
Dir.mkdir(ROOT,0755) unless File.exists?(ROOT)
|
20
18
|
Routinized.upgrade
|
21
|
-
|
22
|
-
|
19
|
+
['master.rb.template','config.json.template'].each do |file|
|
20
|
+
dest_file = file.split(".template").first
|
21
|
+
FileUtils.cp File.join(File.dirname(__FILE__) + "/templates/#{file}"), File.join(ROOT,dest_file)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.command(name,args)
|
26
|
+
Routinized::Commands.send(name.to_sym,args)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self._distribute_files(directory)
|
32
|
+
Dir.chdir(ROOT)
|
33
|
+
Dir.mkdir(directory) unless File.exists?(directory)
|
34
|
+
FileUtils.cp_r Dir.glob(File.dirname(__FILE__) + "/#{directory}/*.rb"), File.join(ROOT,directory), :remove_destination => true
|
35
|
+
return Dir.entries(File.join(ROOT,directory)).select{|f| f =~ /rb/}.map{|x| x.split(".rb").first}
|
23
36
|
end
|
24
37
|
end
|
data/lib/routinized/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'routinized'
|
2
|
-
Dir[File.dirname(__FILE__) + '/
|
2
|
+
Dir[File.dirname(__FILE__) + '/wrappers/*.rb'].each {|file| require file }
|
3
3
|
set :output, "#{Dir.home}/.cron_whenever.log"
|
4
4
|
|
5
5
|
# Morning Routine
|
@@ -11,13 +11,11 @@ every :weekday, :at => '8:00am' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
every :weekday, :at => '8:45am' do
|
14
|
-
command
|
15
|
-
command osx_notify('HN',"Grab a coffee and read Hacker News")
|
14
|
+
command r('rss','https://news.ycombinator.com/rss') + top(10) + pipe + osx_notify('Hacker News')
|
16
15
|
end
|
17
16
|
|
18
17
|
# Stretch Break every 30 minutes during the work week
|
19
18
|
every '*/30 9-16 * * 1-5' do
|
20
|
-
command sleep(5) + say('Time to stretch')
|
21
19
|
command osx_notify('Stretch',"Take a short break and stretch")
|
22
20
|
end
|
23
21
|
|
@@ -42,5 +40,5 @@ end
|
|
42
40
|
|
43
41
|
# Clean out log file, good citizenship!
|
44
42
|
every :day do
|
45
|
-
command "/bin/rm
|
43
|
+
command "/bin/rm #{Dir.home}/.cron_whenever.log"
|
46
44
|
end
|
File without changes
|
@@ -0,0 +1,8 @@
|
|
1
|
+
def osx_notify(title,message = nil)
|
2
|
+
terminal_notifier = Routinized.config['osx_notify']['bin']
|
3
|
+
if message
|
4
|
+
return "#{terminal_notifier} -title \"#{title}\" -message \"#{message}\" "
|
5
|
+
else #piped version
|
6
|
+
return "#{terminal_notifier} -title \"#{title}\" -message"
|
7
|
+
end
|
8
|
+
end
|
data/lib/wrappers/r.rb
ADDED
data/lib/wrappers/say.rb
ADDED
File without changes
|
data/lib/wrappers/top.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routinized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -105,14 +105,18 @@ files:
|
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
107
107
|
- bin/routinized
|
108
|
-
- lib/commands/
|
109
|
-
- lib/commands/osx_notify.rb
|
110
|
-
- lib/commands/say.rb
|
111
|
-
- lib/commands/sleep.rb
|
108
|
+
- lib/commands/rss.rb
|
112
109
|
- lib/routinized.rb
|
113
110
|
- lib/routinized/version.rb
|
114
111
|
- lib/templates/config.json.template
|
115
112
|
- lib/templates/master.rb.template
|
113
|
+
- lib/wrappers/itunes_play.rb
|
114
|
+
- lib/wrappers/osx_notify.rb
|
115
|
+
- lib/wrappers/pipe.rb
|
116
|
+
- lib/wrappers/r.rb
|
117
|
+
- lib/wrappers/say.rb
|
118
|
+
- lib/wrappers/sleep.rb
|
119
|
+
- lib/wrappers/top.rb
|
116
120
|
- routinized.gemspec
|
117
121
|
homepage: http://github.com/zhubert/routinized
|
118
122
|
licenses:
|
data/lib/commands/osx_notify.rb
DELETED
data/lib/commands/say.rb
DELETED