From 34c7ec5649cd4a38a2988a315744c5219a6990a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Pr=C3=A9vost?= Date: Wed, 16 Feb 2011 10:36:09 -0500 Subject: [PATCH] Add `--here` option to create the first window in the current window --- bin/teamocil | 31 ++++++++++++++++++++++++++----- lib/teamocil.rb | 2 +- lib/teamocil/layout.rb | 14 +++++++++----- teamocil.gemspec | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/bin/teamocil b/bin/teamocil index 6e42556..52db55e 100755 --- a/bin/teamocil +++ b/bin/teamocil @@ -1,13 +1,34 @@ #!/usr/bin/env ruby +def bail(msg) + puts msg + exit(1) +end + $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'yaml' require 'teamocil' +require 'optparse' + +bail "You must be in a tmux session to use teamocil" unless ENV["TMUX"] + +options = {} +opts = OptionParser.new do |opts| + opts.banner = "Usage: teamocil [options] + +Options: + " + opts.on("--here", "Set up the first window in the current window") do |safe| + options[:here] = true + end -if ENV["TMUX"] == nil - puts "You must be in a tmux session to use teamocil" -else - layout = Teamocil::Layout.new(ARGV[0], File.join("#{ENV["HOME"]}/.teamocil", "#{ARGV[0]}.yml")) - layout.to_tmux end +opts.parse! + +file = File.join("#{ENV["HOME"]}/.teamocil", "#{ARGV[0]}.yml") + +bail "There is no file \"#{file}\"" unless File.exists?(file) + +layout = Teamocil::Layout.new(file, options) +layout.to_tmux diff --git a/lib/teamocil.rb b/lib/teamocil.rb index 72c6616..57543ec 100644 --- a/lib/teamocil.rb +++ b/lib/teamocil.rb @@ -1,4 +1,4 @@ module Teamocil - VERSION = '0.1.2' + VERSION = '0.1.4' autoload :Layout, "teamocil/layout" end diff --git a/lib/teamocil/layout.rb b/lib/teamocil/layout.rb index 21f4312..7786782 100644 --- a/lib/teamocil/layout.rb +++ b/lib/teamocil/layout.rb @@ -1,11 +1,11 @@ module Teamocil class Layout - attr_accessor :config, :name + attr_accessor :layout, :options - def initialize(name, file) # {{{ + def initialize(file, options) # {{{ @layout = YAML.load_file(file) - @name = name + @options = options end # }}} def to_tmux # {{{ @@ -16,9 +16,13 @@ module Teamocil def generate_commands # {{{ output = [] - @layout["windows"].each do |window| + @layout["windows"].each_with_index do |window, window_index| - output << "tmux new-window -n #{window["name"]}" + if options.include?(:here) and window_index == 0 + output << "tmux rename-window #{window["name"]}" + else + output << "tmux new-window -n #{window["name"]}" + end window["splits"].each_with_index do |split, index| unless index == 0 if split.include?("width") diff --git a/teamocil.gemspec b/teamocil.gemspec index 5fda198..67dd4c8 100644 --- a/teamocil.gemspec +++ b/teamocil.gemspec @@ -1,6 +1,6 @@ spec = Gem::Specification.new do |s| s.name = "teamocil" - s.version = "0.1.2" + s.version = "0.1.4" s.platform = Gem::Platform::RUBY s.authors = "Rémi Prévost" s.email = "remi@exomel.com"