dtachr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/Gemfile +10 -0
  2. data/Gemfile.lock +16 -0
  3. data/LICENSE +20 -0
  4. data/README.md +19 -0
  5. data/Rakefile +150 -0
  6. data/bin/dtachr +6 -0
  7. data/dtachr.gemspec +76 -0
  8. data/lib/dtachr.rb +56 -0
  9. metadata +130 -0
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '1.8.7'
4
+
5
+ gem 'docopt'
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'rdoc'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ docopt (0.5.0)
5
+ json (1.8.1)
6
+ rake (10.1.0)
7
+ rdoc (4.0.1)
8
+ json (~> 1.4)
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ docopt
15
+ rake
16
+ rdoc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Bryan Swift
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ = dtachr
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to dtachr
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Bryan Swift. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rdoc/task'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
84
+ #############################################################################
85
+ #
86
+ # Packaging tasks
87
+ #
88
+ #############################################################################
89
+
90
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push origin v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ desc "Build #{gem_file} into the pkg directory"
104
+ task :build => :gemspec do
105
+ sh "mkdir -p pkg"
106
+ sh "gem build #{gemspec_file}"
107
+ sh "mv #{gem_file} pkg"
108
+ end
109
+
110
+ desc "Generate #{gemspec_file}"
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ desc "Validate #{gemspec_file}"
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
data/bin/dtachr ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'dtachr'
4
+
5
+ dtr = Dtachr::Runner.new(ARGV)
6
+ dtr.call
data/dtachr.gemspec ADDED
@@ -0,0 +1,76 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'dtachr'
16
+ s.version = '0.0.1'
17
+ s.date = '2013-11-08'
18
+ s.rubyforge_project = 'dtachr'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "Short description used in Gem listings."
23
+ s.description = "Long description. Maybe copied from the README."
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["Bryan Swift"]
29
+ s.email = 'bryan.j.swift@gmail.com'
30
+ s.homepage = 'http://github.com/bryanjswift/dtachr'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## This sections is only necessary if you have C extensions.
37
+ # s.require_paths << 'ext'
38
+ # s.extensions = %w[ext/extconf.rb]
39
+
40
+ ## If your gem includes any executables, list them here.
41
+ s.executables = ["dtachr"]
42
+
43
+ ## Specify any RDoc options here. You'll want to add your README and
44
+ ## LICENSE files to the extra_rdoc_files list.
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.extra_rdoc_files = %w[README.md LICENSE]
47
+
48
+ ## List your runtime dependencies here. Runtime dependencies are those
49
+ ## that are needed for an end user to actually USE your code.
50
+ s.add_dependency('docopt', [">= 0.5.0", "< 1.0.0"])
51
+
52
+ ## List your development dependencies here. Development dependencies are
53
+ ## those that are only needed during development
54
+ s.add_development_dependency('rake', ["10.1.0"])
55
+ s.add_development_dependency('rdoc', ["4.0.1"])
56
+
57
+ ## Leave this section as-is. It will be automatically generated from the
58
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
59
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
60
+ # = MANIFEST =
61
+ s.files = %w[
62
+ Gemfile
63
+ Gemfile.lock
64
+ LICENSE
65
+ README.md
66
+ Rakefile
67
+ bin/dtachr
68
+ dtachr.gemspec
69
+ lib/dtachr.rb
70
+ ]
71
+ # = MANIFEST =
72
+
73
+ ## Test files will be grabbed from the file list. Make sure the path glob
74
+ ## matches what you actually use.
75
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
76
+ end
data/lib/dtachr.rb ADDED
@@ -0,0 +1,56 @@
1
+ # Read $HOME/.dtachr for where to put sockets
2
+ # Generate a 256 character file name if a socket isn't given
3
+ # Everything after the optional socket name is the command
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ require 'docopt'
7
+
8
+ module Dtachr
9
+
10
+ VERSION = '0.0.1'
11
+ DOC = <<-DOCOPT
12
+ dtachr
13
+
14
+ Usage:
15
+ #{__FILE__} [--socket=<sock>] <parts>...
16
+ #{__FILE__} -h | --help
17
+ #{__FILE__} -v | --version
18
+
19
+ Options:
20
+ -h --help Show this screen
21
+ -v --version Show the version
22
+ -n --socket=<sock> Temporary file to use as socket for dtach command
23
+
24
+ DOCOPT
25
+
26
+ class Runner
27
+
28
+ def initialize(args)
29
+ @opts = Docopt::docopt(Dtachr::DOC, {
30
+ :argv => args,
31
+ :version => Dtachr::VERSION
32
+ })
33
+ @socket = @opts['socket'] || gen_socket
34
+ @command = @opts['<parts>'].join(' ')
35
+ rescue Docopt::Exit => e
36
+ puts e.message
37
+ end
38
+
39
+ def call
40
+ return unless @opts
41
+ execute("dtach -n #{@socket} #{@command} && terminal-notifier -message '`#{@command}` finished.'")
42
+ end
43
+
44
+ private
45
+
46
+ def execute(command)
47
+ `#{command}`
48
+ end
49
+
50
+ def gen_socket
51
+ "tmp"
52
+ end
53
+
54
+ end
55
+
56
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtachr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Bryan Swift
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-11-08 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: docopt
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 0
32
+ - 5
33
+ - 0
34
+ version: 0.5.0
35
+ - - <
36
+ - !ruby/object:Gem::Version
37
+ hash: 23
38
+ segments:
39
+ - 1
40
+ - 0
41
+ - 0
42
+ version: 1.0.0
43
+ type: :runtime
44
+ version_requirements: *id001
45
+ - !ruby/object:Gem::Dependency
46
+ name: rake
47
+ prerelease: false
48
+ requirement: &id002 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ hash: 75
54
+ segments:
55
+ - 10
56
+ - 1
57
+ - 0
58
+ version: 10.1.0
59
+ type: :development
60
+ version_requirements: *id002
61
+ - !ruby/object:Gem::Dependency
62
+ name: rdoc
63
+ prerelease: false
64
+ requirement: &id003 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - "="
68
+ - !ruby/object:Gem::Version
69
+ hash: 61
70
+ segments:
71
+ - 4
72
+ - 0
73
+ - 1
74
+ version: 4.0.1
75
+ type: :development
76
+ version_requirements: *id003
77
+ description: Long description. Maybe copied from the README.
78
+ email: bryan.j.swift@gmail.com
79
+ executables:
80
+ - dtachr
81
+ extensions: []
82
+
83
+ extra_rdoc_files:
84
+ - README.md
85
+ - LICENSE
86
+ files:
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - bin/dtachr
93
+ - dtachr.gemspec
94
+ - lib/dtachr.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/bryanjswift/dtachr
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --charset=UTF-8
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project: dtachr
125
+ rubygems_version: 1.6.2
126
+ signing_key:
127
+ specification_version: 2
128
+ summary: Short description used in Gem listings.
129
+ test_files: []
130
+