csexton-captured 0.0.0 → 0.1.0

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/bin/captured CHANGED
@@ -5,30 +5,102 @@ require 'optparse'
5
5
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  require 'captured'
7
7
 
8
+ options = {:config_file => "#{ENV['HOME']}/.captured.yml",
9
+ :watch_path => "#{ENV['HOME']}/Desktop/",
10
+ :watch_pattern => "Screenshot**.png",
11
+ :growl_path => "/usr/local/bin/growlnotify" }
12
+
8
13
  OptionParser.new do |opts|
9
14
  opts.summary_width = 25
10
15
 
11
16
  opts.banner = "captured: Quick screen capture and sharing on OS X"
17
+ opts.banner = " <filename> Quick upload"
12
18
 
13
19
  opts.on('--help', "Print this message") do
14
20
  puts "#{opts}\n"
15
21
  exit
16
22
  end
17
23
 
18
- opts.on('--startup', "Run at startup") do
19
- puts "install launchd!"
24
+ opts.on('--config-file=FILE', "Config file (Default: #{options[:config_file]})") do |file|
25
+ options[:config_file] = file
26
+ end
27
+
28
+ opts.on('--watch-path=PATH', "Path to watch (Default: #{options[:watch_path]})") do |path|
29
+ options[:watch_path] = path
30
+ end
31
+
32
+ opts.on('--watch-pattern=PATTERN', "Pattern to match (Default: #{options[:watch_pattern]})") do |path|
33
+ options[:watch_path] = path
34
+ end
35
+
36
+ opts.on('--growlnotify=PATH', "Path to growlnotify (Default: #{options[:growl_path]})") do |file|
37
+ options[:growl_path] = file
38
+ end
39
+
40
+ opts.on('--install', "Run at startup") do
41
+ options[:install] = true
42
+ end
43
+
44
+ opts.on('--remove', "Remove captured from launchd") do
45
+ puts "Uninstalling captured"
46
+ File.delete "#{ENV['HOME']}/Library/LaunchAgents/com.github.csexton.captured"
47
+ system "launchctl remove com.github.csexton.captured"
20
48
  exit
21
49
  end
22
50
 
51
+ opts.on('--launchd', "Indicate that this was invoked via launchd") do
52
+ options[:launchd] = true
53
+ end
54
+
55
+ opts.on('--watch', "Create a run loop that will watch for screenshots") do
56
+ options[:launchd] = true
57
+ end
58
+
23
59
  opts.on('--config', "Install a config file to #{Captured.config_file}") do
24
60
  puts "install config file!"
25
- if (File.exists? Captured.config_file)
61
+ if (!File.exists? Captured.config_file)
26
62
  FileUtils.copy("#{File.dirname(__FILE__)}/../etc/captured.yml-example", Captured.config_file)
27
-
28
63
  end
29
64
  exit
30
65
  end
66
+
31
67
  end.parse!
32
68
 
33
- Captured::run!
69
+ if options[:install] == true
70
+ puts "Installing captured"
71
+ require 'erb'
72
+ require 'pathname'
73
+ if (File.exists? options[:config_file])
74
+ puts "Found existing config file at #{options[:config_file]}"
75
+ else
76
+ FileUtils.copy("#{File.dirname(__FILE__)}/../etc/captured.yml-example", options[:config_file])
77
+ puts "Copied example config file to #{options[:config_file]}"
78
+ end
79
+ program_path = Pathname.new($0).realpath
80
+ watch_path = options[:watch_path]
81
+ plist_path = "#{ENV['HOME']}/Library/LaunchAgents/"
82
+ template = ERB.new(File.open("#{File.dirname(__FILE__)}/../etc/launchd.plist.erb", 'r').read)
83
+ FileUtils.mkdir_p plist_path
84
+ File.open("#{plist_path}/com.github.csexton.captured", 'w') do |f|
85
+ f.write(template.result(binding))
86
+ end
87
+ system "launchctl load ~/Library/LaunchAgents"
88
+ exit
89
+ end
90
+
91
+ if options[:launchd] == true
92
+ Captured::run_once! options
93
+ exit
94
+ end
95
+
96
+ if options[:watch] == true
97
+ Captured::run_and_watch! options
98
+ exit
99
+ end
100
+
101
+ if ARGV[0] && File.exists?(ARGV[0])
102
+ FileUploader.upload(ARGV[0], options)
103
+ exit
104
+ end
34
105
 
106
+ puts "Invalid option, run `captured --help` for usage"
@@ -1,4 +1,50 @@
1
- # Example config
2
- upload:
3
- command: system "scp '#{file}' 'fuzzymonk.com:fuzzymonk.com/captured/#{remote_name}'"
4
- type: eval
1
+ # Example captured configuration file
2
+ #
3
+ # Eval
4
+ # ====
5
+ #
6
+ # Complete control for the complete nerd. This allows you to execute arbtrary
7
+ # ruby code when a matching file is found. Normally this would be used to
8
+ # invoke a command line upload (such as scp, curl, etc).
9
+ #
10
+ # One advantage with calling scp this way is it will be aware of all the custom
11
+ # settings made in ~/.ssh/config.
12
+ #
13
+ # You have access to two local varibles:
14
+ # * file - the local file to upload
15
+ # * remote_name - the hashed name to use on the server
16
+ #
17
+ # Simple scp via eval command
18
+
19
+ #upload:
20
+ # type: eval
21
+ # command: system "scp '#{file}' 'user@example.com:example.com/captured/#{remote_name}'"
22
+ # url: "http://example.com/captured/"
23
+
24
+ # Curl post to twitpic.com
25
+
26
+ #upload:
27
+ # type: eval
28
+ # url: "http://twitter.com/user/"
29
+ # command: |
30
+ # remote_path="http://twitter.com/user"
31
+ # system "curl -F media='@#{file}' -F username=user -F password=secret -F message=Captured http://twitpic.com/api/uploadAndPost"
32
+ #
33
+ # scp
34
+ # ===
35
+ #
36
+ # Standard scp, using the ruby net/ssh library.
37
+ #
38
+ # * user - optinal if your remote user is the same as your local user
39
+ # * password - optional if you have setup key pair authentication
40
+ # * host - the remote host name
41
+ # * url - the public url to the remote host+path
42
+ # * path - the remote path to upload to
43
+
44
+ #upload:
45
+ # type: scp
46
+ # user: user
47
+ # host: example.com
48
+ # path: example.com/captured/
49
+ # url: "http://example.com/captured/"
50
+
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key>
6
+ <string>com.github.csexton.captured</string>
7
+ <key>LowPriorityIO</key>
8
+ <true/>
9
+ <key>Program</key>
10
+ <string><%= program_path %></string>
11
+ <key>ProgramArguments</key>
12
+ <array>
13
+ <string>captured</string>
14
+ <string>--launchd</string>
15
+ </array>
16
+ <key>WatchPaths</key>
17
+ <array>
18
+ <string><%= watch_path %></string>
19
+ </array>
20
+ </dict>
21
+ </plist>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csexton-captured
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Sexton
@@ -9,14 +9,13 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-23 00:00:00 -07:00
13
- default_executable:
12
+ date: 2009-06-25 00:00:00 -07:00
13
+ default_executable: captured
14
14
  dependencies: []
15
15
 
16
16
  description:
17
17
  email: csexton@gmail.com
18
18
  executables:
19
- - capture
20
19
  - captured
21
20
  extensions: []
22
21
 
@@ -25,6 +24,7 @@ extra_rdoc_files:
25
24
  - README.markdown
26
25
  files:
27
26
  - etc/captured.yml-example
27
+ - etc/launchd.plist.erb
28
28
  - LICENSE
29
29
  - README.markdown
30
30
  has_rdoc: false
@@ -48,11 +48,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  version:
49
49
  requirements: []
50
50
 
51
- rubyforge_project:
51
+ rubyforge_project: captured
52
52
  rubygems_version: 1.2.0
53
53
  signing_key:
54
54
  specification_version: 3
55
- summary: TODO
55
+ summary: Quick screenshot sharing for OS X
56
56
  test_files:
57
57
  - spec/captured_spec.rb
58
58
  - spec/spec_helper.rb
data/bin/capture DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require 'optparse'
4
-
5
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
- require 'captured'
7
-
8
- FileUploader.upload(ARGV[0])