autoterm 0.2.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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rjpaskin+git@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in autoterm.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Rob Paskin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Autoterm
2
+
3
+ **WARNING** alpha software! Use at your own risk.
4
+
5
+ Automate the setup of your iTerm2 tabs. Project still in early development.
6
+
7
+ ## Installation
8
+
9
+ $ gem install autoterm
10
+
11
+ ## Usage
12
+
13
+ Currently only [Tmuxinator](https://github.com/tmuxinator/tmuxinator) projects are supported, and only the `root` and `windows` (without panes) keys are supported.
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
18
+
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rjpaskin/autoterm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
28
+
29
+ ## Code of Conduct
30
+
31
+ Everyone interacting in the Autoterm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/autoterm/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/autoterm.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "autoterm/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "autoterm"
8
+ spec.version = Autoterm::VERSION
9
+ spec.authors = ["Rob Paskin"]
10
+ spec.email = ["rjpaskin@gmail.com"]
11
+
12
+ spec.summary = %q{CLI tool to automate creation of iTerm2 sessions}
13
+ spec.homepage = "https://github.com/rjpaskin/autoterm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry-byebug"
27
+ end
data/bin/console ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "autoterm"
5
+
6
+ module Kernel
7
+ private
8
+
9
+ def reload!
10
+ old_verbose, $VERBOSE = $VERBOSE, nil
11
+
12
+ $LOADED_FEATURES.grep(%r{/autoterm/}).each do |file|
13
+ $LOADED_FEATURES.delete(file)
14
+ require file
15
+ end
16
+
17
+ true
18
+ ensure
19
+ $VERBOSE = old_verbose
20
+ end
21
+ end
22
+
23
+ require "pry"
24
+ Pry.start
data/bin/rspec ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/autoterm ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path("../../lib/", __FILE__)
3
+
4
+ require "autoterm"
5
+
6
+ Autoterm::CLI.run(ARGV)
data/lib/autoterm.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "autoterm/version"
2
+ require "autoterm/errors"
3
+
4
+ module Autoterm
5
+ autoload :OSAScript, "autoterm/osascript"
6
+ autoload :CLI, "autoterm/cli"
7
+ autoload :Tab, "autoterm/tab"
8
+ autoload :TmuxinatorProject, "autoterm/tmuxinator_project"
9
+ end
@@ -0,0 +1,18 @@
1
+ tell application "iTerm"
2
+ activate
3
+ create window with default profile
4
+ tell current window
5
+ <%- tabs.each_with_index do |tab, index| -%>
6
+ <%- unless index.zero? %>
7
+ create tab with default profile
8
+ <%- end -%>
9
+ tell current session
10
+ set name to "<%= escape tab.name %>"
11
+ write text "cd <%= escape root %>"
12
+ <%- tab.commands.each do |command| -%>
13
+ write text "<%= escape command %>"
14
+ <%- end -%>
15
+ end tell
16
+ <%- end -%>
17
+ end tell
18
+ end tell
@@ -0,0 +1,36 @@
1
+ module Autoterm
2
+ class CLI
3
+ def self.run(args)
4
+ new(args).run
5
+ end
6
+
7
+ def initialize(args)
8
+ @args = args
9
+ end
10
+
11
+ def run
12
+ if project_name.to_s.length.zero?
13
+ error! "Provide a project name"
14
+ end
15
+
16
+ OSAScript.new(
17
+ TmuxinatorProject.from_yaml_file(project_name)
18
+ ).run
19
+ rescue Error => error
20
+ error! error
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :args
26
+
27
+ def project_name
28
+ @project_name ||= args[0]
29
+ end
30
+
31
+ def error!(message)
32
+ $stderr.puts message
33
+ Kernel.exit 1
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ module Autoterm
2
+ class Error < StandardError; end
3
+
4
+ class ProjectNotFoundError < Error
5
+ attr_reader :project_name, :filename
6
+
7
+ def initialize(project_name, filename)
8
+ super "Unable to find project '#{project_name}', tried to load #{filename}"
9
+
10
+ @project_name = project_name
11
+ @filename = filename
12
+ end
13
+ end
14
+
15
+ class ParseError < Error
16
+ def initialize(project_name, original)
17
+ super "Unable to parse project file '#{project_name}':\n #{original.class}:#{original.message}"
18
+
19
+ @project_name = project_name
20
+ end
21
+ end
22
+
23
+ class ExecutionError < Error
24
+ def initialize(stderr)
25
+ super "Error whilst running project:\n #{stderr}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ require "delegate"
2
+ require "erb"
3
+ require "open3"
4
+
5
+ module Autoterm
6
+ class OSAScript
7
+ attr_reader :project
8
+
9
+ TEMPLATE_PATH = File.expand_path(
10
+ "../assets/applescript.erb", __FILE__
11
+ ).freeze
12
+
13
+ def initialize(project)
14
+ @project = project
15
+ end
16
+
17
+ def render
18
+ ERB.new(template, nil, "-").result(RenderContext.for(project))
19
+ end
20
+
21
+ def run
22
+ _stdout, stderr, status = Open3.capture3(
23
+ "osascript -",
24
+ stdin_data: render
25
+ )
26
+
27
+ raise ExecutionError.new(stderr) unless status.success?
28
+ end
29
+
30
+ private
31
+
32
+ def template
33
+ File.read(TEMPLATE_PATH)
34
+ end
35
+
36
+ class RenderContext < SimpleDelegator
37
+ def self.for(project)
38
+ new(project).instance_eval { binding }
39
+ end
40
+
41
+ private
42
+
43
+ def escape(string)
44
+ string.to_s.gsub(%{"}, %{\\"})
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ module Autoterm
2
+ class Tab
3
+ attr_reader :name, :commands
4
+
5
+ def initialize(name, commands)
6
+ @name = name.to_s
7
+ @commands = Array(commands).flatten.select do |cmd|
8
+ cmd.to_s.length.nonzero?
9
+ end
10
+ end
11
+
12
+ def ==(other)
13
+ return false unless self.class === other
14
+
15
+ name == other.name && commands == other.commands
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ require "yaml"
2
+ require "erb"
3
+
4
+ module Autoterm
5
+ class TmuxinatorProject
6
+ def self.from_yaml_file(project_name)
7
+ filename = "#{ENV["HOME"]}/.tmuxinator/#{project_name}.yml"
8
+ content = File.read(filename)
9
+
10
+ # These instance variables could be used in a template,
11
+ # so set to empty objects just in case
12
+ @args = []
13
+ @settings = {}
14
+ parsed_content = ERB.new(content, nil, "-").result(binding)
15
+
16
+ new(YAML.load(parsed_content))
17
+ rescue Errno::ENOENT
18
+ raise ProjectNotFoundError.new(project_name, filename)
19
+ rescue SyntaxError, StandardError => error
20
+ raise ParseError.new(project_name, error)
21
+ end
22
+
23
+ attr_reader :config
24
+
25
+ def initialize(config)
26
+ @config = config
27
+ end
28
+
29
+ def root
30
+ config["root"]
31
+ end
32
+
33
+ def tabs
34
+ @tabs ||= config["windows"].map do |window|
35
+ name, commands = window.first
36
+
37
+ if commands.is_a? Hash
38
+ panes = Array(commands["pre"]) + Array(commands["panes"])
39
+
40
+ # Ignore panes for now, flatten commands
41
+ commands = panes.map do |pane|
42
+ pane.is_a?(Hash) ? pane.values.flatten : pane
43
+ end
44
+ end
45
+
46
+ Tab.new(name, commands)
47
+ end
48
+ end
49
+ end
50
+ end