commit 1f0d2fe405c60ba9aa259d1698b9422c1ebf6626 Author: Rémi Prévost Date: Sat Feb 5 13:11:38 2011 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d32b9e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.gem +.rvmrc +.local* diff --git a/README.mkd b/README.mkd new file mode 100644 index 0000000..efd359a --- /dev/null +++ b/README.mkd @@ -0,0 +1,35 @@ +# What is this? + +Teamocil is a tool used to automatically create windows and splits in `tmux` with Ruby and YAML. Like [tmuxinator](https://github.com/aziz/tmuxinator), but with splits, not just windows. + +A work in progress. Will be a gem soon. You probably should not use it. Things will change. + +# Usage + + $ teamocil sample + +# Layout example + + # ~/.teamocil/sample.yml + + - cmd: cd ~/Code/sample/www + - cmd: + - cd ~/Code/sample/www + - rails s + width: 50 + - cmd: memcached -p 11211 -vv + height: 25 + +will create a new window named `sample` with a layout like this: + + .------------------.------------------. + | (0) | (1) | + | | | + | | | + | | | + | | | + | | | + | |------------------| + | | (2) | + | | | + '------------------'------------------' diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e69de29 diff --git a/bin/teamocil b/bin/teamocil new file mode 100755 index 0000000..2c9b4e1 --- /dev/null +++ b/bin/teamocil @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require "teamocil" + +layout = Teamocil::Layout.new(ARGV[0], File.join("#{ENV["HOME"]}/.teamocil", "#{ARGV[0]}.yml")) +layout.to_tmux diff --git a/lib/teamocil.rb b/lib/teamocil.rb new file mode 100644 index 0000000..2ebc680 --- /dev/null +++ b/lib/teamocil.rb @@ -0,0 +1,9 @@ +require 'yaml' + +$:.unshift(File.dirname(__FILE__)) unless + $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) + +module Teamocil + VERSION = '0.1' + autoload :Layout, "teamocil/layout" +end diff --git a/lib/teamocil/layout.rb b/lib/teamocil/layout.rb new file mode 100644 index 0000000..21f4312 --- /dev/null +++ b/lib/teamocil/layout.rb @@ -0,0 +1,52 @@ +module Teamocil + class Layout + + attr_accessor :config, :name + + def initialize(name, file) # {{{ + @layout = YAML.load_file(file) + @name = name + end # }}} + + def to_tmux # {{{ + commands = generate_commands + execute_commands(commands) + end # }}} + + def generate_commands # {{{ + output = [] + + @layout["windows"].each do |window| + + output << "tmux new-window -n #{window["name"]}" + window["splits"].each_with_index do |split, index| + unless index == 0 + if split.include?("width") + output << "tmux split-window -h -p #{split["width"]}" + else + if split.include?("height") + output << "tmux split-window -p #{split["height"]}" + else + output << "tmux split-window" + end + end + end + + split["cmd"] = [split["cmd"]] unless split["cmd"].is_a? Array + split["cmd"].each do |command| + output << "tmux send-keys -t #{index} \"#{command}\"" + output << "tmux send-keys -t #{index} Enter" + end + end + + end + + output << "tmux select-pane -t 0" + end # }}} + + def execute_commands(commands) # {{{ + `#{commands.join("; ")}` + end # }}} + + end +end diff --git a/script/console b/script/console new file mode 100755 index 0000000..cd23ed8 --- /dev/null +++ b/script/console @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +# File: script/console +irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' + +libs = " -r irb/completion" +# Perhaps use a console_lib to store any extra methods I may want available in the cosole +# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}" +libs << " -r #{File.dirname(__FILE__) + '/../lib/teamocil.rb'}" +puts "Loading teamocil gem" +exec "#{irb} #{libs} --simple-prompt" \ No newline at end of file diff --git a/teamocil.gemspec b/teamocil.gemspec new file mode 100644 index 0000000..698c061 --- /dev/null +++ b/teamocil.gemspec @@ -0,0 +1,14 @@ +spec = Gem::Specification.new do |s| + s.name = "teamocil" + s.version = "0.1" + s.platform = Gem::Platform::RUBY + s.authors = "Rémi Prévost" + s.email = "remi@exomel.com" + s.homepage = "http://github.com/remiprev/teamocil" + s.summary = "Easy window and split layouts for tmux" + s.description = "Teamocil helps you set up window and splits layouts for tmux using YAML configuration files." + s.files = Dir["lib/**/*.rb", "README.mkd", "LICENSE", "bin/*"] + s.require_path = "lib" + s.executables << 'teamocil' +end + diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..1e7fecc --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +require 'stringio' +require 'test/unit' +require File.dirname(__FILE__) + '/../lib/teamocil' diff --git a/test/test_teamocil.rb b/test/test_teamocil.rb new file mode 100644 index 0000000..30ab737 --- /dev/null +++ b/test/test_teamocil.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/test_helper.rb' + +class TestTeamocil < Test::Unit::TestCase + + def setup + end + + def test_truth + assert true + end +end