tummy 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/Tmuxfile +20 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/tummy +120 -0
- data/lib/tummy/version.rb +3 -0
- data/lib/tummy.rb +5 -0
- data/tummy.gemspec +31 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91f1a601abc4899d8ab8aa940915e543b3cd94e9
|
4
|
+
data.tar.gz: dafdb56c839f51102ac008e012933f661f85c8d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5a59c6ba2fd8d9e3d5507abd490711c4ae50dc5b0cb58607662798f5724b59e712a92897adbcc47b38bfcec4e5833498575acdafa96236446d37460c3a11ad0
|
7
|
+
data.tar.gz: 384d24aad9173ce4c129a4e351eb78325c2ccfe288c66abf70a5b39d0fb307b8884789dbc580a063524fe4a2b1033e7d1b84323a9ec477f3b354c4b70eb7cabd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Tummy
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tummy`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'tummy'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install tummy
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tummy.
|
36
|
+
|
data/Rakefile
ADDED
data/Tmuxfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
session "z2-web"
|
2
|
+
directory "/home/minhajuddin/z2/web"
|
3
|
+
|
4
|
+
window "src", [
|
5
|
+
pane("vim TODO"),
|
6
|
+
]
|
7
|
+
|
8
|
+
window "server-iex", [
|
9
|
+
pane("iex -S mix phoenix.server"),
|
10
|
+
pane("iex -S mix", :horizontal),
|
11
|
+
pane("git status", :vertical),
|
12
|
+
]
|
13
|
+
|
14
|
+
window "play", [
|
15
|
+
pane("echo hey"),
|
16
|
+
pane("date", :horizontal),
|
17
|
+
pane("echo awesome", :vertical),
|
18
|
+
]
|
19
|
+
|
20
|
+
# vim: filetype=ruby
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tummy"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/tummy
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
attr_reader :tmux
|
5
|
+
def initialize(tmux)
|
6
|
+
@tmux = tmux
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
# if this session is already open let us attach it to that
|
11
|
+
attach_to_running_session
|
12
|
+
create_session
|
13
|
+
create_windows
|
14
|
+
focus_first_window
|
15
|
+
attach_to_running_session
|
16
|
+
end
|
17
|
+
|
18
|
+
def session; tmux.session_name end
|
19
|
+
def directory; tmux.directory_name end
|
20
|
+
|
21
|
+
def focus_first_window
|
22
|
+
run_cmd "tmux select-window -t #{session}:0"
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_session
|
26
|
+
run_cmd "tmux new-session -d -s #{session} -c #{directory} -n #{tmux.windows.first.name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_windows
|
30
|
+
# the first window is already created
|
31
|
+
create_panes(tmux.windows.first)
|
32
|
+
tmux.windows.drop(1).each{|window| create_window(window)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_window(window)
|
36
|
+
run_cmd "tmux new-window -n #{window.name} -t #{session} -c #{directory}"
|
37
|
+
create_panes(window)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_panes(window)
|
41
|
+
# the first pane is already created
|
42
|
+
panes = window.panes
|
43
|
+
run_cmd "tmux send-keys -t #{session} \"#{panes.first.cmd}\" C-m"
|
44
|
+
panes.drop(1).each do |pane|
|
45
|
+
run_cmd "tmux split-window #{"-h" if pane.alignment == :vertical} -t #{session}:#{window.index} -c #{directory}"
|
46
|
+
run_cmd "tmux send-keys -t #{session}:#{window.index}.#{pane.index} \"#{pane.cmd}\" C-m"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def attach_to_running_session
|
51
|
+
if run_cmd("tmux has-session -t #{session}")
|
52
|
+
exec "tmux attach-session -t #{session}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_cmd(cmd)
|
57
|
+
puts "> #{cmd}"
|
58
|
+
system(cmd)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Tmux
|
63
|
+
|
64
|
+
attr_reader :windows
|
65
|
+
|
66
|
+
def initialize(filepath)
|
67
|
+
@filepath = filepath
|
68
|
+
@windows = []
|
69
|
+
end
|
70
|
+
|
71
|
+
def run
|
72
|
+
config = File.read(@filepath)
|
73
|
+
self.instance_eval config
|
74
|
+
Runner.new(self).run
|
75
|
+
end
|
76
|
+
|
77
|
+
def session(name)
|
78
|
+
@session = name
|
79
|
+
end
|
80
|
+
|
81
|
+
def session_name; @session end
|
82
|
+
def directory_name; @directory end
|
83
|
+
|
84
|
+
def directory(directory)
|
85
|
+
@directory = directory
|
86
|
+
end
|
87
|
+
|
88
|
+
Window = Struct.new(:name, :panes, :index)
|
89
|
+
def window(name, panes)
|
90
|
+
@windows << Window.new(name, panes.each_with_index.map{|x, i| x.index = i; x}, @windows.length)
|
91
|
+
end
|
92
|
+
|
93
|
+
Pane = Struct.new(:cmd, :alignment, :index)
|
94
|
+
def pane(cmd, alignment = :vertical)
|
95
|
+
Pane.new(cmd, alignment, 0)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# init a Tmuxfile
|
100
|
+
cmd = ARGV.first
|
101
|
+
if cmd.to_s.strip.downcase == "init"
|
102
|
+
if File.exists?("Tmuxfile")
|
103
|
+
puts "ERROR: Tmuxfile is already present in the current directory"
|
104
|
+
exit(-1)
|
105
|
+
end
|
106
|
+
|
107
|
+
require 'fileutils'
|
108
|
+
FileUtils.cp File.expand_path(File.join(__FILE__, "../../Tmuxfile")), "."
|
109
|
+
puts "created a Tmuxfile in the current directory"
|
110
|
+
exit(0)
|
111
|
+
end
|
112
|
+
|
113
|
+
# open a session
|
114
|
+
file = "Tmuxfile" || ARGV.first
|
115
|
+
if !file || !File.exists?(file)
|
116
|
+
puts "#{file} not found in current directory"
|
117
|
+
puts "you can initialize a new file by running `tummy init`"
|
118
|
+
exit(-1)
|
119
|
+
end
|
120
|
+
Tmux.new(file).run
|
data/lib/tummy.rb
ADDED
data/tummy.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tummy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tummy"
|
8
|
+
spec.version = Tummy::VERSION
|
9
|
+
spec.authors = ["Khaja Minhajuddin"]
|
10
|
+
spec.email = ["minhajuddin@cosmicvent.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{use a Tmuxfile to create a tmux sessino}
|
13
|
+
spec.homepage = "https://minhajuddin.com"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tummy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Khaja Minhajuddin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- minhajuddin@cosmicvent.com
|
58
|
+
executables:
|
59
|
+
- tummy
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- Tmuxfile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- exe/tummy
|
73
|
+
- lib/tummy.rb
|
74
|
+
- lib/tummy/version.rb
|
75
|
+
- tummy.gemspec
|
76
|
+
homepage: https://minhajuddin.com
|
77
|
+
licenses: []
|
78
|
+
metadata:
|
79
|
+
allowed_push_host: https://rubygems.org
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.8
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: use a Tmuxfile to create a tmux sessino
|
100
|
+
test_files: []
|