# HG changeset patch # User Yasutaka Higa # Date 1405899120 -32400 # Node ID 67a6071afec7a40a9b670ec15c205a2e2b055806 # Parent 107d94e009cc387b17fd965f8de1f620a620b7a8 Rename tmuxinator -> pmuxinator $ zmv **/*tmuxinator* **/*pmuxinator* $ gsed -e 's/tmuxinator/pmuxinator/g' -i **/*.* $ gsed -e 's/Tmuxinator/Pmuxinator/g' -i **/*.* diff -r 107d94e009cc -r 67a6071afec7 CHANGELOG.md --- a/CHANGELOG.md Mon Jul 21 08:29:18 2014 +0900 +++ b/CHANGELOG.md Mon Jul 21 08:32:00 2014 +0900 @@ -7,7 +7,7 @@ ## 0.6.7 - Remove use of grep for base-index #171 -- Fix bugs in `Tmuxinator::Config.default?` #169 +- Fix bugs in `Pmuxinator::Config.default?` #169 - Fix path for Rails log in directory sample #177 - Add completions for fish shell #179 - Fix grammar in readme #184 @@ -42,12 +42,12 @@ ## 0.6.4 - Fixes broken backwards compatibility of multiple pre commands #129 -- Fixes tmuxinator ignoring project root when started from within a tmux session #132 +- Fixes pmuxinator ignoring project root when started from within a tmux session #132 - Add gem version badge ## 0.6.3 - Remove stray pry #128 -- Allow starting a tmuxinator project while inside a tmux session #130 +- Allow starting a pmuxinator project while inside a tmux session #130 - Set the tmux layout after pane creation to avoid pane too small errors #131 - Check for both pane-base-index and base-index #126 diff -r 107d94e009cc -r 67a6071afec7 CONTRIBUTING.md --- a/CONTRIBUTING.md Mon Jul 21 08:29:18 2014 +0900 +++ b/CONTRIBUTING.md Mon Jul 21 08:32:00 2014 +0900 @@ -3,7 +3,7 @@ ## First * Check if the issue you're going to submit isn't already submitted in - the [Issues](https://github.com/aziz/tmuxinator/issues) page. + the [Issues](https://github.com/aziz/pmuxinator/issues) page. ## Issues diff -r 107d94e009cc -r 67a6071afec7 README.md --- a/README.md Mon Jul 21 08:29:18 2014 +0900 +++ b/README.md Mon Jul 21 08:32:00 2014 +0900 @@ -1,6 +1,6 @@ -# Tmuxinator +# Pmuxinator -[![Gem Version](https://badge.fury.io/rb/tmuxinator.png)](http://badge.fury.io/rb/tmuxinator) [![Build Status](https://secure.travis-ci.org/tmuxinator/tmuxinator.png)](http://travis-ci.org/tmuxinator/tmuxinator?branch=master) [![Coverage Status](https://coveralls.io/repos/tmuxinator/tmuxinator/badge.png)](https://coveralls.io/r/tmuxinator/tmuxinator) [![Code Climate](https://codeclimate.com/github/tmuxinator/tmuxinator.png)](https://codeclimate.com/github/tmuxinator/tmuxinator) [![Dependency Status](https://gemnasium.com/tmuxinator/tmuxinator.png)](https://gemnasium.com/tmuxinator/tmuxinator) +[![Gem Version](https://badge.fury.io/rb/pmuxinator.png)](http://badge.fury.io/rb/pmuxinator) [![Build Status](https://secure.travis-ci.org/pmuxinator/pmuxinator.png)](http://travis-ci.org/pmuxinator/pmuxinator?branch=master) [![Coverage Status](https://coveralls.io/repos/pmuxinator/pmuxinator/badge.png)](https://coveralls.io/r/pmuxinator/pmuxinator) [![Code Climate](https://codeclimate.com/github/pmuxinator/pmuxinator.png)](https://codeclimate.com/github/pmuxinator/pmuxinator) [![Dependency Status](https://gemnasium.com/pmuxinator/pmuxinator.png)](https://gemnasium.com/pmuxinator/pmuxinator) Create and manage tmux sessions easily. @@ -9,12 +9,12 @@ ## Installation ``` -gem install tmuxinator +gem install pmuxinator ``` ## Editor and Shell -tmuxinator uses your shell's default editor for opening files. If you're not +pmuxinator uses your shell's default editor for opening files. If you're not sure what that is type: ``` bash @@ -51,19 +51,19 @@ Add the following to your `~/.bashrc`: - source ~/.bin/tmuxinator.bash + source ~/.bin/pmuxinator.bash ### zsh Add the following to your `~/.zshrc`: - source ~/.bin/tmuxinator.zsh + source ~/.bin/pmuxinator.zsh ### fish -Move `tmuxinator.fish` to your `completions` folder: +Move `pmuxinator.fish` to your `completions` folder: - cp ~/.bin/tmuxinator.fish ~/.config/completions/ + cp ~/.bin/pmuxinator.fish ~/.config/completions/ ## Usage @@ -75,15 +75,15 @@ Create or edit your projects with: ``` -tmuxinator new [project] +pmuxinator new [project] ``` -For editing you can also use `tmuxinator open [project]`. `new` is aliased to +For editing you can also use `pmuxinator open [project]`. `new` is aliased to `o`,`open` and `n`. Your default editor (`$EDITOR`) is used to open the file. If this is a new project you will see this default config: ```yaml -# ~/.tmuxinator/sample.yml +# ~/.pmuxinator/sample.yml name: sample root: ~/ @@ -126,7 +126,7 @@ ## Panes **_Note that if you wish to use panes, make sure that you do not have `.` in your project name. tmux uses `.` to delimit between window and pane indices, -and tmuxinator uses the project name in combination with these indices to target the correct pane or window._** +and pmuxinator uses the project name in combination with these indices to target the correct pane or window._** Panes are optional and are children of window entries, but unlike windows, they do not need a name. In the following example, the `editor` window has 2 panes, one running vim, the other guard. @@ -145,7 +145,7 @@ ## Interpreter Managers & Environment Variables -To use tmuxinator with rbenv, RVM, NVM etc, use the `pre_window` option. +To use pmuxinator with rbenv, RVM, NVM etc, use the `pre_window` option. ``` pre_window: rbenv shell 2.0.0-p247 @@ -155,7 +155,7 @@ ## Passing directly to send-keys -tmuxinator passes commands directly to send keys. This differs from simply chaining commands together using `&&` or `;`, in that +pmuxinator passes commands directly to send keys. This differs from simply chaining commands together using `&&` or `;`, in that tmux will directly send the commands to a shell as if you typed them in. This allows commands to be executed on a remote server over SSH for example. @@ -183,12 +183,12 @@ This will fire up tmux with all the tabs and panes you configured. ``` -tmuxinator start [project] +pmuxinator start [project] ``` ## Shorthand -A shorthand alias for tmuxinator can also be used. +A shorthand alias for pmuxinator can also be used. ``` mux [command] @@ -198,42 +198,42 @@ Copy an existing project. Aliased to `c` and `cp` ``` -tmuxinator copy [existing] [new] +pmuxinator copy [existing] [new] ``` List all the projects you have configured. Aliased to `l` and `ls` ``` -tmuxinator list +pmuxinator list ``` Remove a project. Aliased to `rm` ``` -tmuxinator delete [project] +pmuxinator delete [project] ``` -Remove all tmuxinator configs, aliases and scripts. Aliased to `i` +Remove all pmuxinator configs, aliases and scripts. Aliased to `i` ``` -tmuxinator implode +pmuxinator implode ``` Examines your environment and identifies problems with your configuration ``` -tmuxinator doctor +pmuxinator doctor ``` -Shows tmuxinator's help. Aliased to `h` +Shows pmuxinator's help. Aliased to `h` ``` -tmuxinator help +pmuxinator help ``` Shows the shell commands that get executed for a project ``` -tmuxinator debug [project] +pmuxinator debug [project] ``` -Shows tmuxinator's version. +Shows pmuxinator's version. ``` -tmuxinator version +pmuxinator version ``` ## FAQ @@ -244,7 +244,7 @@ ## Contributing -To contribute, please read the [contributing guide](https://github.com/tmuxinator/tmuxinator/blob/master/CONTRIBUTING.md). +To contribute, please read the [contributing guide](https://github.com/pmuxinator/pmuxinator/blob/master/CONTRIBUTING.md). ## Copyright diff -r 107d94e009cc -r 67a6071afec7 bin/pmuxinator --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/pmuxinator Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +$: << File.expand_path("../../lib/", __FILE__) + +require "thor" +require "tmuxinator" + +if ARGV.length == 1 + name = ARGV[0] + + if Tmuxinator::Cli.new.command_list.include?(name) + Tmuxinator::Cli.start + elsif Tmuxinator::Config.exists?(name) + Tmuxinator::Cli.new.start(name) + else + Tmuxinator::Cli.start + end +else + Tmuxinator::Cli.start +end diff -r 107d94e009cc -r 67a6071afec7 bin/tmuxinator --- a/bin/tmuxinator Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby -$: << File.expand_path("../../lib/", __FILE__) - -require "thor" -require "tmuxinator" - -if ARGV.length == 1 - name = ARGV[0] - - if Tmuxinator::Cli.new.command_list.include?(name) - Tmuxinator::Cli.start - elsif Tmuxinator::Config.exists?(name) - Tmuxinator::Cli.new.start(name) - else - Tmuxinator::Cli.start - end -else - Tmuxinator::Cli.start -end diff -r 107d94e009cc -r 67a6071afec7 completion/pmuxinator.bash --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/completion/pmuxinator.bash Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +_pmuxinator() { + COMPREPLY=() + local word="${COMP_WORDS[COMP_CWORD]}" + + if [ "$COMP_CWORD" -eq 1 ]; then + local commands="$(compgen -W "$(pmuxinator commands)" -- "$word")" + local projects="$(compgen -W "$(pmuxinator completions start)" -- "$word")" + + COMPREPLY=( $commands $projects ) + else + local words=("${COMP_WORDS[@]}") + unset words[0] + unset words[$COMP_CWORD] + local completions=$(pmuxinator completions "${words[@]}") + COMPREPLY=( $(compgen -W "$completions" -- "$word") ) + fi +} + +complete -F _pmuxinator pmuxinator mux diff -r 107d94e009cc -r 67a6071afec7 completion/pmuxinator.fish --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/completion/pmuxinator.fish Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,16 @@ +function __fish_pmuxinator_using_command + set cmd (commandline -opc) + if [ (count $cmd) -gt 1 ] + if [ $argv[1] = $cmd[2] ] + return 0 + end + end + return 1 +end + +complete -f -c pmuxinator -a '(pmuxinator completions start)' +complete -f -c pmuxinator -a '(pmuxinator commands)' +complete -f -c pmuxinator -n '__fish_pmuxinator_using_command start' -a '(pmuxinator completions start)' +complete -f -c pmuxinator -n '__fish_pmuxinator_using_command open' -a '(pmuxinator completions open)' +complete -f -c pmuxinator -n '__fish_pmuxinator_using_command copy' -a '(pmuxinator completions copy)' +complete -f -c pmuxinator -n '__fish_pmuxinator_using_command delete' -a '(pmuxinator completions delete)' diff -r 107d94e009cc -r 67a6071afec7 completion/pmuxinator.zsh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/completion/pmuxinator.zsh Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +if [[ ! -o interactive ]]; then + return +fi + +compctl -K _pmuxinator pmuxinator mux + +_pmuxinator() { + local words completions + read -cA words + + if [ "${#words}" -eq 2 ]; then + completions="$(pmuxinator commands)" + else + completions="$(pmuxinator completions ${words[2,-2]})" + fi + + reply=("${(ps:\n:)completions}") +} diff -r 107d94e009cc -r 67a6071afec7 completion/tmuxinator.bash --- a/completion/tmuxinator.bash Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -_tmuxinator() { - COMPREPLY=() - local word="${COMP_WORDS[COMP_CWORD]}" - - if [ "$COMP_CWORD" -eq 1 ]; then - local commands="$(compgen -W "$(tmuxinator commands)" -- "$word")" - local projects="$(compgen -W "$(tmuxinator completions start)" -- "$word")" - - COMPREPLY=( $commands $projects ) - else - local words=("${COMP_WORDS[@]}") - unset words[0] - unset words[$COMP_CWORD] - local completions=$(tmuxinator completions "${words[@]}") - COMPREPLY=( $(compgen -W "$completions" -- "$word") ) - fi -} - -complete -F _tmuxinator tmuxinator mux diff -r 107d94e009cc -r 67a6071afec7 completion/tmuxinator.fish --- a/completion/tmuxinator.fish Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function __fish_tmuxinator_using_command - set cmd (commandline -opc) - if [ (count $cmd) -gt 1 ] - if [ $argv[1] = $cmd[2] ] - return 0 - end - end - return 1 -end - -complete -f -c tmuxinator -a '(tmuxinator completions start)' -complete -f -c tmuxinator -a '(tmuxinator commands)' -complete -f -c tmuxinator -n '__fish_tmuxinator_using_command start' -a '(tmuxinator completions start)' -complete -f -c tmuxinator -n '__fish_tmuxinator_using_command open' -a '(tmuxinator completions open)' -complete -f -c tmuxinator -n '__fish_tmuxinator_using_command copy' -a '(tmuxinator completions copy)' -complete -f -c tmuxinator -n '__fish_tmuxinator_using_command delete' -a '(tmuxinator completions delete)' diff -r 107d94e009cc -r 67a6071afec7 completion/tmuxinator.zsh --- a/completion/tmuxinator.zsh Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -#!/usr/bin/env zsh - -if [[ ! -o interactive ]]; then - return -fi - -compctl -K _tmuxinator tmuxinator mux - -_tmuxinator() { - local words completions - read -cA words - - if [ "${#words}" -eq 2 ]; then - completions="$(tmuxinator commands)" - else - completions="$(tmuxinator completions ${words[2,-2]})" - fi - - reply=("${(ps:\n:)completions}") -} diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,24 @@ +require "yaml" +require "erubis" +require "shellwords" +require "thor" +require "thor/version" + +require "pmuxinator/util" +require "pmuxinator/deprecations" +require "pmuxinator/wemux_support" +require "pmuxinator/cli" +require "pmuxinator/config" +require "pmuxinator/pane" +require "pmuxinator/project" +require "pmuxinator/window" +require "pmuxinator/version" + +module Pmuxinator +end + +class Object + def blank? + respond_to?(:empty?) ? !!empty? : !self + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/assets/sample.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/assets/sample.yml Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,28 @@ +# ~/.pmuxinator/<%= name %>.yml + +name: <%= name %> +root: ~/ + +# Optional tmux socket +# socket_name: foo + +# Runs before everything. Use it to start daemons etc. +# pre: sudo /etc/rc.d/mysqld start + +# Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions. +# pre_window: rbenv shell 2.0.0-p247 + +# Pass command line options to tmux. Useful for specifying a different tmux.conf. +# tmux_options: -f ~/.tmux.mac.conf + +# Change the command to call tmux. This can be used by derivatives/wrappers like byobu. +# tmux_command: byobu + +windows: + - editor: + layout: main-vertical + panes: + - vim + - guard + - server: bundle exec rails s + - logs: tail -f log/development.log diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/assets/template.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/assets/template.erb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,67 @@ +#!<%= ENV["SHELL"] || "/bin/bash" %> + +# Clear rbenv variables before starting tmux +unset RBENV_VERSION +unset RBENV_DIR + +<%= tmux %> start-server\; has-session -t <%= name %> 2>/dev/null + +if [ "$?" -eq 1 ]; then + cd <%= root || "." %> + + # Run pre command. + <%= pre %> + + # Create the session and the first window. + TMUX= <%= tmux %> new-session -d -s <%= name %> -n <%= windows.first.name %> + + <%- if Pmuxinator::Config.version < 1.7 -%> + # Set the default path for versions prior to 1.7 + <%- if root? -%> + <%= tmux %> set-option -t <%= name %> <%= Pmuxinator::Config.default_path_option %> <%= root.shellescape -%> 1>/dev/null + <%- end -%> + <%- end -%> + + # Create other windows. + <%- windows.drop(1).each do |window| -%> + <%= window.tmux_new_window_command %> + <%- end -%> + + <%- windows.each do |window| -%> + + # Window "<%= window.name %>" + <%- unless window.panes? -%> + <%= window.tmux_pre_window_command %> + <%- window.commands.each do |command| -%> + <%= command %> + <%- end -%> + <%- else -%> + <%- window.panes.each do |pane| -%> + <%= pane.tmux_pre_window_command %> + <%= pane.tmux_pre_command %> + <%- if pane.multiple_commands? %> + <%- pane.commands.each do |command| -%> + <%= pane.tmux_main_command(command) %> + <%- end -%> + <%- else -%> + <%= pane.tmux_main_command(commands.first) %> + <%- end -%> + + <%- unless pane.last? -%> + <%= pane.tmux_split_command %> + <%- end -%> + <%= window.tmux_layout_command %> + <%- end -%> + + <%= window.tmux_select_first_pane %> + <%- end -%> + <%- end -%> + + <%= tmux %> select-window -t <%= base_index %> +fi + +if [ -z "$TMUX" ]; then + <%= tmux %> -u attach-session -t <%= name %> +else + <%= tmux %> -u switch-client -t <%= name %> +fi diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/assets/wemux_template.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/assets/wemux_template.erb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,56 @@ +#!<%= ENV["SHELL"] || "/bin/bash" %> +wemux ls 2>/dev/null + +if [ "$?" -eq 127 ]; then + cd <%= root || "." %> + + # Run pre command. + <%= pre %> + + # Create the session and the first window. + TMUX= <%= tmux %> new-session -d -s <%= name %> -n <%= windows.first.name %> + + # Set the default path. + <%- if root? -%> + <%= tmux %> set-option -t <%= name %> <%= Pmuxinator::Config.default_path_option %> <%= root.shellescape -%> 1>/dev/null + <%- end -%> + + # Create other windows. + <%- windows.drop(1).each do |window| -%> + <%= window.tmux_new_window_command %> + <%- end -%> + + <%- windows.each do |window| -%> + + # Window "<%= window.name %>" + <%- unless window.panes? -%> + <%= window.tmux_pre_window_command %> + <%- window.commands.each do |command| -%> + <%= command %> + <%- end -%> + <%- else -%> + <%- window.panes.each do |pane| -%> + <%= pane.tmux_pre_window_command %> + <%= pane.tmux_pre_command %> + <%- if pane.multiple_commands? %> + <%- pane.commands.each do |command| -%> + <%= pane.tmux_main_command(command) %> + <%- end -%> + <%- else -%> + <%= pane.tmux_main_command(commands.first) %> + <%- end -%> + + <%- unless pane.last? -%> + <%= pane.tmux_split_command %> + <%- end -%> + <%= window.tmux_layout_command %> + <%- end -%> + + <%= window.tmux_select_first_pane %> + <%- end -%> + <%- end -%> + + <%= tmux %> select-window -t <%= base_index %> +fi + +wemux attach diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/cli.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/cli.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,147 @@ +module Pmuxinator + class Cli < Thor + include Pmuxinator::Util + + attr_reader :command_list + + def initialize(*args) + super + @command_list = %w(commands copy debug delete doctor help implode list start version) + end + + package_name "pmuxinator" unless Gem::Version.create(Thor::VERSION) < Gem::Version.create("0.18") + + desc "commands", "Lists commands available in pmuxinator" + + def commands + puts command_list.join("\n") + end + + desc "completions [arg1 arg2]", "Used for shell completion" + + def completions(arg) + if %w(start open copy delete).include?(arg) + configs = Pmuxinator::Config.configs + puts configs + end + end + + desc "new [PROJECT]", "Create a new project file and open it in your editor" + map "open" => :new + map "o" => :new + map "n" => :new + + def new(name) + config = Pmuxinator::Config.project(name) + + unless Pmuxinator::Config.exists?(name) + template = Pmuxinator::Config.default? ? Pmuxinator::Config.default : Pmuxinator::Config.sample + erb = Erubis::Eruby.new(File.read(template)).result(binding) + File.open(config, "w") { |f| f.write(erb) } + end + + Kernel.system("$EDITOR #{config}") || doctor + end + + desc "start [PROJECT]", "Start a tmux session using a project's pmuxinator config" + map "s" => :start + + def start(name) + project = Pmuxinator::Config.validate(name) + + if project.deprecations.any? + project.deprecations.each { |deprecation| say deprecation, :red } + puts + print "Press ENTER to continue." + STDIN.getc + end + + Kernel.exec(project.render) + end + + desc "debug [PROJECT]", "Output the shell commands that are generated by pmuxinator" + + def debug(name) + project = Pmuxinator::Config.validate(name) + puts project.render + end + + desc "copy [EXISTING] [NEW]", "Copy an existing project to a new project and open it in your editor" + map "c" => :copy + map "cp" => :copy + + def copy(existing, new) + existing_config_path = Pmuxinator::Config.project(existing) + new_config_path = Pmuxinator::Config.project(new) + + exit!("Project #{existing} doesn't exist!") unless Pmuxinator::Config.exists?(existing) + + if Pmuxinator::Config.exists?(new) + if yes?("#{new} already exists, would you like to overwrite it?", :red) + FileUtils.rm(new_config_path) + say "Overwriting #{new}" + end + end + + FileUtils.copy_file(existing_config_path, new_config_path) + Kernel.system("$EDITOR #{new_config_path}") + end + + desc "delete [PROJECT]", "Deletes given project" + map "d" => :delete + map "rm" => :delete + + def delete(project) + if Pmuxinator::Config.exists?(project) + config = "#{Pmuxinator::Config.root}/#{project}.yml" + + if yes?("Are you sure you want to delete #{project}?(y/n)", :red) + FileUtils.rm(config) + say "Deleted #{project}" + end + else + exit! "That file doesn't exist." + end + end + + desc "implode", "Deletes all pmuxinator projects" + map "i" => :implode + + def implode + if yes?("Are you sure you want to delete all pmuxinator configs?", :red) + FileUtils.remove_dir(Pmuxinator::Config.root) + say "Deleted all pmuxinator projects." + end + end + + desc "list", "Lists all pmuxinator projects" + map "l" => :list + map "ls" => :list + + def list + say "pmuxinator projects:" + + print_in_columns Pmuxinator::Config.configs + end + + desc "version", "Display installed pmuxinator version" + map "-v" => :version + + def version + say "pmuxinator #{Pmuxinator::VERSION}" + end + + desc "doctor", "Look for problems in your configuration" + + def doctor + say "Checking if tmux is installed ==> " + yes_no Pmuxinator::Config.installed? + + say "Checking if $EDITOR is set ==> " + yes_no Pmuxinator::Config.editor? + + say "Checking if $SHELL is set ==> " + yes_no Pmuxinator::Config.shell? + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/config.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/config.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,96 @@ +module Pmuxinator + class Config + class << self + def root + Dir.mkdir("#{ENV["HOME"]}/.pmuxinator") unless File.directory?(File.expand_path("~/.pmuxinator")) + "#{ENV["HOME"]}/.pmuxinator" + end + + def sample + "#{File.dirname(__FILE__)}/assets/sample.yml" + end + + def default + "#{ENV["HOME"]}/.pmuxinator/default.yml" + end + + def default? + exists?("default") + end + + def installed? + Kernel.system("type tmux > /dev/null") + end + + def version + `tmux -V`.split(" ")[1].to_f if installed? + end + + def default_path_option + version && version < 1.7 ? "default-path" : "-c" + end + + def editor? + !ENV["EDITOR"].nil? && !ENV["EDITOR"].empty? + end + + def shell? + !ENV["SHELL"].nil? && !ENV["SHELL"].empty? + end + + def exists?(name) + File.exists?(project(name)) + end + + def project(name) + projects = Dir.glob("#{root}/**/*.yml") + project_file = projects.detect { |project| project =~ /^#{name}.yml$/ } + project_file || "#{root}/#{name}.yml" + end + + def template + "#{File.dirname(__FILE__)}/assets/template.erb" + end + + def wemux_template + "#{File.dirname(__FILE__)}/assets/wemux_template.erb" + end + + def configs + Dir["#{Pmuxinator::Config.root}/*.yml"].sort.map do |path| + File.basename(path, ".yml") + end + end + + def validate(name) + unless Pmuxinator::Config.exists?(name) + puts "Project #{name} doesn't exist." + exit! + end + + config_path = Pmuxinator::Config.project(name) + + yaml = begin + YAML.load(File.read(config_path)) + rescue SyntaxError, StandardError + puts "Failed to parse config file. Please check your formatting." + exit! + end + + project = Pmuxinator::Project.new(yaml) + + unless project.windows? + puts "Your project file should include some windows." + exit! + end + + unless project.name? + puts "Your project file didn't specify a 'project_name'" + exit! + end + + project + end + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/deprecations.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/deprecations.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,19 @@ +module Pmuxinator + module Deprecations + def rvm? + yaml["rvm"] + end + + def rbenv? + yaml["rbenv"] + end + + def pre_tab? + yaml["pre_tab"] + end + + def cli_args? + yaml["cli_args"] + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/pane.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/pane.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,40 @@ +module Pmuxinator + class Pane + attr_reader :commands, :project, :index, :project, :tab + + def initialize(index, project, tab, *commands) + @commands = commands + @index = index + @project = project + @tab = tab + end + + def tmux_window_and_pane_target + "#{project.name}:#{tab.index + project.base_index}.#{index + project.base_index}" + end + + def tmux_pre_command + tab.pre ? "#{project.tmux} send-keys -t #{tmux_window_and_pane_target} #{tab.pre.shellescape} C-m" : "" + end + + def tmux_pre_window_command + project.pre_window ? "#{project.tmux} send-keys -t #{tmux_window_and_pane_target} #{project.pre_window.shellescape} C-m" : "" + end + + def tmux_main_command(command) + command ? "#{project.tmux} send-keys -t #{project.name}:#{tab.index + project.base_index}.#{index + tab.project.base_index} #{command.shellescape} C-m" : "" + end + + def tmux_split_command + "#{project.tmux} splitw -t #{tab.tmux_window_target}" + end + + def last? + index == tab.panes.length - 1 + end + + def multiple_commands? + commands && commands.length > 0 + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/project.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/project.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,174 @@ +module Pmuxinator + class Project + include Pmuxinator::Util + include Pmuxinator::Deprecations + include Pmuxinator::WemuxSupport + + attr_reader :yaml + + def initialize(yaml) + @yaml = yaml + load_wemux_overrides if wemux? + end + + def render + template = File.read(Pmuxinator::Config.template) + Erubis::Eruby.new(template).result(binding) + end + + def windows + windows_yml = yaml["tabs"] || yaml["windows"] + + @windows ||= windows_yml.map.with_index do |window_yml, index| + Pmuxinator::Window.new(window_yml, index, self) + end + end + + def root + root = yaml["project_root"] || yaml["root"] + root.blank? ? nil : File.expand_path(root) + end + + def name + name = yaml["project_name"] || yaml["name"] + name.shellescape + end + + def pre + pre_config = yaml["pre"] + if pre_config.is_a?(Array) + pre_config.join("; ") + else + pre_config + end + end + + def pre_window + if rbenv? + "rbenv shell #{yaml["rbenv"]}" + elsif rvm? + "rvm use #{yaml["rvm"]}" + elsif pre_tab? + yaml["pre_tab"] + else + yaml["pre_window"] + end + end + + def tmux + "#{tmux_command}#{tmux_options}#{socket}" + end + + def tmux_command + yaml["tmux_command"] || "tmux" + end + + def socket + if socket_path + " -S #{socket_path}" + elsif socket_name + " -L #{socket_name}" + else + nil + end + end + + def socket_name + yaml["socket_name"] + end + + def socket_path + yaml["socket_path"] + end + + def tmux_options + if cli_args? + " #{yaml["cli_args"].to_s.strip}" + elsif tmux_options? + " #{yaml["tmux_options"].to_s.strip}" + else + "" + end + end + + def base_index + get_pane_base_index ? get_pane_base_index.to_i : get_base_index.to_i + end + + def tmux_options? + yaml["tmux_options"] + end + + def windows? + windows.any? + end + + def root? + !root.nil? + end + + def name? + !name.nil? + end + + def window(i) + "#{name}:#{i}" + end + + def send_pane_command(cmd, window_index, pane_index) + if cmd.empty? + "" + else + "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m" + end + end + + def send_keys(cmd, window_index) + if cmd.empty? + "" + else + "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m" + end + end + + def deprecations + deprecations = [] + deprecations << "DEPRECATION: rbenv/rvm specific options have been replaced by the pre_tab option and will not be supported in 0.8.0." if yaml["rbenv"] || yaml["rvm"] + deprecations << "DEPRECATION: The tabs option has been replaced by the windows option and will not be supported in 0.8.0." if yaml["tabs"] + deprecations << "DEPRECATION: The cli_args option has been replaced by the tmux_options option and will not be supported in 0.8.0." if yaml["cli_args"] + deprecations + end + + def get_pane_base_index + tmux_config["pane-base-index"] + end + + def get_base_index + tmux_config["base-index"] + end + + def show_tmux_options + "#{tmux} start-server\\; show-option -g" + end + + private + + def tmux_config + @tmux_config ||= extract_tmux_config + end + + def extract_tmux_config + options_hash = {} + + options_string = `#{show_tmux_options}` + options_string.encode!("UTF-8", :invalid => :replace) + options_string.split("\n").map do |entry| + key, value = entry.split("\s") + options_hash[key] = value + options_hash + end + + options_hash + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/util.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/util.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,14 @@ +module Pmuxinator + module Util + include Thor::Actions + + def exit!(msg) + puts msg + Kernel.exit(1) + end + + def yes_no(condition) + condition ? say("Yes", :green) : say("No", :red) + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/version.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/version.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,3 @@ +module Pmuxinator + VERSION = "0.6.8" +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/wemux_support.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/wemux_support.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,24 @@ +module Pmuxinator + module WemuxSupport + def wemux? + yaml["tmux_command"] == "wemux" + end + + def load_wemux_overrides + self.instance_eval do + def render + template = File.read(Pmuxinator::Config.wemux_template) + Erubis::Eruby.new(template).result(binding) + end + + def name + "wemux" + end + + def tmux + "wemux" + end + end + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/pmuxinator/window.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pmuxinator/window.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,90 @@ +module Pmuxinator + class Window + include Pmuxinator::Util + + attr_reader :name, :panes, :layout, :commands, :index, :project + + def initialize(window_yaml, index, project) + @name = !window_yaml.keys.first.nil? ? window_yaml.keys.first.shellescape : nil + @panes = [] + @layout = nil + @pre = nil + @project = project + @index = index + + value = window_yaml.values.first + + if value.is_a?(Hash) + @layout = value["layout"] ? value["layout"].shellescape : nil + @pre = value["pre"] if value["pre"] + + @panes = build_panes(value["panes"]) + else + @commands = build_commands(tmux_window_command_prefix, value) + end + end + + def build_panes(panes_yml) + Array(panes_yml).map.with_index do |pane_yml, index| + if pane_yml.is_a?(Hash) + pane_yml.map do |name, commands| + Pmuxinator::Pane.new(index, project, self, *commands) + end + else + Pmuxinator::Pane.new(index, project, self, pane_yml) + end + end.flatten + end + + def build_commands(prefix, command_yml) + if command_yml.is_a?(Array) + command_yml.map do |command| + "#{tmux_window_command_prefix} #{command.shellescape} C-m" if command + end.compact + elsif command_yml.is_a?(String) && !command_yml.empty? + ["#{tmux_window_command_prefix} #{command_yml.shellescape} C-m"] + else + [] + end + end + + def pre + if @pre.is_a?(Array) + @pre.join(" && ") + elsif @pre.is_a?(String) + @pre + else + "" + end + end + + def panes? + panes.any? + end + + def tmux_window_target + "#{project.name}:#{index + project.base_index}" + end + + def tmux_pre_window_command + project.pre_window ? "#{project.tmux} send-keys -t #{tmux_window_target} #{project.pre_window.shellescape} C-m" : "" + end + + def tmux_window_command_prefix + "#{project.tmux} send-keys -t #{project.name}:#{index + project.base_index}" + end + + def tmux_new_window_command + path = project.root? ? "#{Pmuxinator::Config.default_path_option} #{File.expand_path(project.root).shellescape}" : nil + "#{project.tmux} new-window #{path} -t #{tmux_window_target} -n #{name}" + end + + def tmux_layout_command + "#{project.tmux} select-layout -t #{tmux_window_target} #{layout}" + end + + def tmux_select_first_pane + "#{project.tmux} select-pane -t #{tmux_window_target}.#{panes.first.index + project.base_index}" + end + end +end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator.rb --- a/lib/tmuxinator.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -require "yaml" -require "erubis" -require "shellwords" -require "thor" -require "thor/version" - -require "tmuxinator/util" -require "tmuxinator/deprecations" -require "tmuxinator/wemux_support" -require "tmuxinator/cli" -require "tmuxinator/config" -require "tmuxinator/pane" -require "tmuxinator/project" -require "tmuxinator/window" -require "tmuxinator/version" - -module Tmuxinator -end - -class Object - def blank? - respond_to?(:empty?) ? !!empty? : !self - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/assets/sample.yml --- a/lib/tmuxinator/assets/sample.yml Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -# ~/.tmuxinator/<%= name %>.yml - -name: <%= name %> -root: ~/ - -# Optional tmux socket -# socket_name: foo - -# Runs before everything. Use it to start daemons etc. -# pre: sudo /etc/rc.d/mysqld start - -# Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions. -# pre_window: rbenv shell 2.0.0-p247 - -# Pass command line options to tmux. Useful for specifying a different tmux.conf. -# tmux_options: -f ~/.tmux.mac.conf - -# Change the command to call tmux. This can be used by derivatives/wrappers like byobu. -# tmux_command: byobu - -windows: - - editor: - layout: main-vertical - panes: - - vim - - guard - - server: bundle exec rails s - - logs: tail -f log/development.log diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/assets/template.erb --- a/lib/tmuxinator/assets/template.erb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -#!<%= ENV["SHELL"] || "/bin/bash" %> - -# Clear rbenv variables before starting tmux -unset RBENV_VERSION -unset RBENV_DIR - -<%= tmux %> start-server\; has-session -t <%= name %> 2>/dev/null - -if [ "$?" -eq 1 ]; then - cd <%= root || "." %> - - # Run pre command. - <%= pre %> - - # Create the session and the first window. - TMUX= <%= tmux %> new-session -d -s <%= name %> -n <%= windows.first.name %> - - <%- if Tmuxinator::Config.version < 1.7 -%> - # Set the default path for versions prior to 1.7 - <%- if root? -%> - <%= tmux %> set-option -t <%= name %> <%= Tmuxinator::Config.default_path_option %> <%= root.shellescape -%> 1>/dev/null - <%- end -%> - <%- end -%> - - # Create other windows. - <%- windows.drop(1).each do |window| -%> - <%= window.tmux_new_window_command %> - <%- end -%> - - <%- windows.each do |window| -%> - - # Window "<%= window.name %>" - <%- unless window.panes? -%> - <%= window.tmux_pre_window_command %> - <%- window.commands.each do |command| -%> - <%= command %> - <%- end -%> - <%- else -%> - <%- window.panes.each do |pane| -%> - <%= pane.tmux_pre_window_command %> - <%= pane.tmux_pre_command %> - <%- if pane.multiple_commands? %> - <%- pane.commands.each do |command| -%> - <%= pane.tmux_main_command(command) %> - <%- end -%> - <%- else -%> - <%= pane.tmux_main_command(commands.first) %> - <%- end -%> - - <%- unless pane.last? -%> - <%= pane.tmux_split_command %> - <%- end -%> - <%= window.tmux_layout_command %> - <%- end -%> - - <%= window.tmux_select_first_pane %> - <%- end -%> - <%- end -%> - - <%= tmux %> select-window -t <%= base_index %> -fi - -if [ -z "$TMUX" ]; then - <%= tmux %> -u attach-session -t <%= name %> -else - <%= tmux %> -u switch-client -t <%= name %> -fi diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/assets/wemux_template.erb --- a/lib/tmuxinator/assets/wemux_template.erb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -#!<%= ENV["SHELL"] || "/bin/bash" %> -wemux ls 2>/dev/null - -if [ "$?" -eq 127 ]; then - cd <%= root || "." %> - - # Run pre command. - <%= pre %> - - # Create the session and the first window. - TMUX= <%= tmux %> new-session -d -s <%= name %> -n <%= windows.first.name %> - - # Set the default path. - <%- if root? -%> - <%= tmux %> set-option -t <%= name %> <%= Tmuxinator::Config.default_path_option %> <%= root.shellescape -%> 1>/dev/null - <%- end -%> - - # Create other windows. - <%- windows.drop(1).each do |window| -%> - <%= window.tmux_new_window_command %> - <%- end -%> - - <%- windows.each do |window| -%> - - # Window "<%= window.name %>" - <%- unless window.panes? -%> - <%= window.tmux_pre_window_command %> - <%- window.commands.each do |command| -%> - <%= command %> - <%- end -%> - <%- else -%> - <%- window.panes.each do |pane| -%> - <%= pane.tmux_pre_window_command %> - <%= pane.tmux_pre_command %> - <%- if pane.multiple_commands? %> - <%- pane.commands.each do |command| -%> - <%= pane.tmux_main_command(command) %> - <%- end -%> - <%- else -%> - <%= pane.tmux_main_command(commands.first) %> - <%- end -%> - - <%- unless pane.last? -%> - <%= pane.tmux_split_command %> - <%- end -%> - <%= window.tmux_layout_command %> - <%- end -%> - - <%= window.tmux_select_first_pane %> - <%- end -%> - <%- end -%> - - <%= tmux %> select-window -t <%= base_index %> -fi - -wemux attach diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/cli.rb --- a/lib/tmuxinator/cli.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -module Tmuxinator - class Cli < Thor - include Tmuxinator::Util - - attr_reader :command_list - - def initialize(*args) - super - @command_list = %w(commands copy debug delete doctor help implode list start version) - end - - package_name "tmuxinator" unless Gem::Version.create(Thor::VERSION) < Gem::Version.create("0.18") - - desc "commands", "Lists commands available in tmuxinator" - - def commands - puts command_list.join("\n") - end - - desc "completions [arg1 arg2]", "Used for shell completion" - - def completions(arg) - if %w(start open copy delete).include?(arg) - configs = Tmuxinator::Config.configs - puts configs - end - end - - desc "new [PROJECT]", "Create a new project file and open it in your editor" - map "open" => :new - map "o" => :new - map "n" => :new - - def new(name) - config = Tmuxinator::Config.project(name) - - unless Tmuxinator::Config.exists?(name) - template = Tmuxinator::Config.default? ? Tmuxinator::Config.default : Tmuxinator::Config.sample - erb = Erubis::Eruby.new(File.read(template)).result(binding) - File.open(config, "w") { |f| f.write(erb) } - end - - Kernel.system("$EDITOR #{config}") || doctor - end - - desc "start [PROJECT]", "Start a tmux session using a project's tmuxinator config" - map "s" => :start - - def start(name) - project = Tmuxinator::Config.validate(name) - - if project.deprecations.any? - project.deprecations.each { |deprecation| say deprecation, :red } - puts - print "Press ENTER to continue." - STDIN.getc - end - - Kernel.exec(project.render) - end - - desc "debug [PROJECT]", "Output the shell commands that are generated by tmuxinator" - - def debug(name) - project = Tmuxinator::Config.validate(name) - puts project.render - end - - desc "copy [EXISTING] [NEW]", "Copy an existing project to a new project and open it in your editor" - map "c" => :copy - map "cp" => :copy - - def copy(existing, new) - existing_config_path = Tmuxinator::Config.project(existing) - new_config_path = Tmuxinator::Config.project(new) - - exit!("Project #{existing} doesn't exist!") unless Tmuxinator::Config.exists?(existing) - - if Tmuxinator::Config.exists?(new) - if yes?("#{new} already exists, would you like to overwrite it?", :red) - FileUtils.rm(new_config_path) - say "Overwriting #{new}" - end - end - - FileUtils.copy_file(existing_config_path, new_config_path) - Kernel.system("$EDITOR #{new_config_path}") - end - - desc "delete [PROJECT]", "Deletes given project" - map "d" => :delete - map "rm" => :delete - - def delete(project) - if Tmuxinator::Config.exists?(project) - config = "#{Tmuxinator::Config.root}/#{project}.yml" - - if yes?("Are you sure you want to delete #{project}?(y/n)", :red) - FileUtils.rm(config) - say "Deleted #{project}" - end - else - exit! "That file doesn't exist." - end - end - - desc "implode", "Deletes all tmuxinator projects" - map "i" => :implode - - def implode - if yes?("Are you sure you want to delete all tmuxinator configs?", :red) - FileUtils.remove_dir(Tmuxinator::Config.root) - say "Deleted all tmuxinator projects." - end - end - - desc "list", "Lists all tmuxinator projects" - map "l" => :list - map "ls" => :list - - def list - say "tmuxinator projects:" - - print_in_columns Tmuxinator::Config.configs - end - - desc "version", "Display installed tmuxinator version" - map "-v" => :version - - def version - say "tmuxinator #{Tmuxinator::VERSION}" - end - - desc "doctor", "Look for problems in your configuration" - - def doctor - say "Checking if tmux is installed ==> " - yes_no Tmuxinator::Config.installed? - - say "Checking if $EDITOR is set ==> " - yes_no Tmuxinator::Config.editor? - - say "Checking if $SHELL is set ==> " - yes_no Tmuxinator::Config.shell? - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/config.rb --- a/lib/tmuxinator/config.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -module Tmuxinator - class Config - class << self - def root - Dir.mkdir("#{ENV["HOME"]}/.tmuxinator") unless File.directory?(File.expand_path("~/.tmuxinator")) - "#{ENV["HOME"]}/.tmuxinator" - end - - def sample - "#{File.dirname(__FILE__)}/assets/sample.yml" - end - - def default - "#{ENV["HOME"]}/.tmuxinator/default.yml" - end - - def default? - exists?("default") - end - - def installed? - Kernel.system("type tmux > /dev/null") - end - - def version - `tmux -V`.split(" ")[1].to_f if installed? - end - - def default_path_option - version && version < 1.7 ? "default-path" : "-c" - end - - def editor? - !ENV["EDITOR"].nil? && !ENV["EDITOR"].empty? - end - - def shell? - !ENV["SHELL"].nil? && !ENV["SHELL"].empty? - end - - def exists?(name) - File.exists?(project(name)) - end - - def project(name) - projects = Dir.glob("#{root}/**/*.yml") - project_file = projects.detect { |project| project =~ /^#{name}.yml$/ } - project_file || "#{root}/#{name}.yml" - end - - def template - "#{File.dirname(__FILE__)}/assets/template.erb" - end - - def wemux_template - "#{File.dirname(__FILE__)}/assets/wemux_template.erb" - end - - def configs - Dir["#{Tmuxinator::Config.root}/*.yml"].sort.map do |path| - File.basename(path, ".yml") - end - end - - def validate(name) - unless Tmuxinator::Config.exists?(name) - puts "Project #{name} doesn't exist." - exit! - end - - config_path = Tmuxinator::Config.project(name) - - yaml = begin - YAML.load(File.read(config_path)) - rescue SyntaxError, StandardError - puts "Failed to parse config file. Please check your formatting." - exit! - end - - project = Tmuxinator::Project.new(yaml) - - unless project.windows? - puts "Your project file should include some windows." - exit! - end - - unless project.name? - puts "Your project file didn't specify a 'project_name'" - exit! - end - - project - end - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/deprecations.rb --- a/lib/tmuxinator/deprecations.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -module Tmuxinator - module Deprecations - def rvm? - yaml["rvm"] - end - - def rbenv? - yaml["rbenv"] - end - - def pre_tab? - yaml["pre_tab"] - end - - def cli_args? - yaml["cli_args"] - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/pane.rb --- a/lib/tmuxinator/pane.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -module Tmuxinator - class Pane - attr_reader :commands, :project, :index, :project, :tab - - def initialize(index, project, tab, *commands) - @commands = commands - @index = index - @project = project - @tab = tab - end - - def tmux_window_and_pane_target - "#{project.name}:#{tab.index + project.base_index}.#{index + project.base_index}" - end - - def tmux_pre_command - tab.pre ? "#{project.tmux} send-keys -t #{tmux_window_and_pane_target} #{tab.pre.shellescape} C-m" : "" - end - - def tmux_pre_window_command - project.pre_window ? "#{project.tmux} send-keys -t #{tmux_window_and_pane_target} #{project.pre_window.shellescape} C-m" : "" - end - - def tmux_main_command(command) - command ? "#{project.tmux} send-keys -t #{project.name}:#{tab.index + project.base_index}.#{index + tab.project.base_index} #{command.shellescape} C-m" : "" - end - - def tmux_split_command - "#{project.tmux} splitw -t #{tab.tmux_window_target}" - end - - def last? - index == tab.panes.length - 1 - end - - def multiple_commands? - commands && commands.length > 0 - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/project.rb --- a/lib/tmuxinator/project.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -module Tmuxinator - class Project - include Tmuxinator::Util - include Tmuxinator::Deprecations - include Tmuxinator::WemuxSupport - - attr_reader :yaml - - def initialize(yaml) - @yaml = yaml - load_wemux_overrides if wemux? - end - - def render - template = File.read(Tmuxinator::Config.template) - Erubis::Eruby.new(template).result(binding) - end - - def windows - windows_yml = yaml["tabs"] || yaml["windows"] - - @windows ||= windows_yml.map.with_index do |window_yml, index| - Tmuxinator::Window.new(window_yml, index, self) - end - end - - def root - root = yaml["project_root"] || yaml["root"] - root.blank? ? nil : File.expand_path(root) - end - - def name - name = yaml["project_name"] || yaml["name"] - name.shellescape - end - - def pre - pre_config = yaml["pre"] - if pre_config.is_a?(Array) - pre_config.join("; ") - else - pre_config - end - end - - def pre_window - if rbenv? - "rbenv shell #{yaml["rbenv"]}" - elsif rvm? - "rvm use #{yaml["rvm"]}" - elsif pre_tab? - yaml["pre_tab"] - else - yaml["pre_window"] - end - end - - def tmux - "#{tmux_command}#{tmux_options}#{socket}" - end - - def tmux_command - yaml["tmux_command"] || "tmux" - end - - def socket - if socket_path - " -S #{socket_path}" - elsif socket_name - " -L #{socket_name}" - else - nil - end - end - - def socket_name - yaml["socket_name"] - end - - def socket_path - yaml["socket_path"] - end - - def tmux_options - if cli_args? - " #{yaml["cli_args"].to_s.strip}" - elsif tmux_options? - " #{yaml["tmux_options"].to_s.strip}" - else - "" - end - end - - def base_index - get_pane_base_index ? get_pane_base_index.to_i : get_base_index.to_i - end - - def tmux_options? - yaml["tmux_options"] - end - - def windows? - windows.any? - end - - def root? - !root.nil? - end - - def name? - !name.nil? - end - - def window(i) - "#{name}:#{i}" - end - - def send_pane_command(cmd, window_index, pane_index) - if cmd.empty? - "" - else - "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m" - end - end - - def send_keys(cmd, window_index) - if cmd.empty? - "" - else - "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m" - end - end - - def deprecations - deprecations = [] - deprecations << "DEPRECATION: rbenv/rvm specific options have been replaced by the pre_tab option and will not be supported in 0.8.0." if yaml["rbenv"] || yaml["rvm"] - deprecations << "DEPRECATION: The tabs option has been replaced by the windows option and will not be supported in 0.8.0." if yaml["tabs"] - deprecations << "DEPRECATION: The cli_args option has been replaced by the tmux_options option and will not be supported in 0.8.0." if yaml["cli_args"] - deprecations - end - - def get_pane_base_index - tmux_config["pane-base-index"] - end - - def get_base_index - tmux_config["base-index"] - end - - def show_tmux_options - "#{tmux} start-server\\; show-option -g" - end - - private - - def tmux_config - @tmux_config ||= extract_tmux_config - end - - def extract_tmux_config - options_hash = {} - - options_string = `#{show_tmux_options}` - options_string.encode!("UTF-8", :invalid => :replace) - options_string.split("\n").map do |entry| - key, value = entry.split("\s") - options_hash[key] = value - options_hash - end - - options_hash - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/util.rb --- a/lib/tmuxinator/util.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -module Tmuxinator - module Util - include Thor::Actions - - def exit!(msg) - puts msg - Kernel.exit(1) - end - - def yes_no(condition) - condition ? say("Yes", :green) : say("No", :red) - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/version.rb --- a/lib/tmuxinator/version.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -module Tmuxinator - VERSION = "0.6.8" -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/wemux_support.rb --- a/lib/tmuxinator/wemux_support.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -module Tmuxinator - module WemuxSupport - def wemux? - yaml["tmux_command"] == "wemux" - end - - def load_wemux_overrides - self.instance_eval do - def render - template = File.read(Tmuxinator::Config.wemux_template) - Erubis::Eruby.new(template).result(binding) - end - - def name - "wemux" - end - - def tmux - "wemux" - end - end - end - end -end diff -r 107d94e009cc -r 67a6071afec7 lib/tmuxinator/window.rb --- a/lib/tmuxinator/window.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -module Tmuxinator - class Window - include Tmuxinator::Util - - attr_reader :name, :panes, :layout, :commands, :index, :project - - def initialize(window_yaml, index, project) - @name = !window_yaml.keys.first.nil? ? window_yaml.keys.first.shellescape : nil - @panes = [] - @layout = nil - @pre = nil - @project = project - @index = index - - value = window_yaml.values.first - - if value.is_a?(Hash) - @layout = value["layout"] ? value["layout"].shellescape : nil - @pre = value["pre"] if value["pre"] - - @panes = build_panes(value["panes"]) - else - @commands = build_commands(tmux_window_command_prefix, value) - end - end - - def build_panes(panes_yml) - Array(panes_yml).map.with_index do |pane_yml, index| - if pane_yml.is_a?(Hash) - pane_yml.map do |name, commands| - Tmuxinator::Pane.new(index, project, self, *commands) - end - else - Tmuxinator::Pane.new(index, project, self, pane_yml) - end - end.flatten - end - - def build_commands(prefix, command_yml) - if command_yml.is_a?(Array) - command_yml.map do |command| - "#{tmux_window_command_prefix} #{command.shellescape} C-m" if command - end.compact - elsif command_yml.is_a?(String) && !command_yml.empty? - ["#{tmux_window_command_prefix} #{command_yml.shellescape} C-m"] - else - [] - end - end - - def pre - if @pre.is_a?(Array) - @pre.join(" && ") - elsif @pre.is_a?(String) - @pre - else - "" - end - end - - def panes? - panes.any? - end - - def tmux_window_target - "#{project.name}:#{index + project.base_index}" - end - - def tmux_pre_window_command - project.pre_window ? "#{project.tmux} send-keys -t #{tmux_window_target} #{project.pre_window.shellescape} C-m" : "" - end - - def tmux_window_command_prefix - "#{project.tmux} send-keys -t #{project.name}:#{index + project.base_index}" - end - - def tmux_new_window_command - path = project.root? ? "#{Tmuxinator::Config.default_path_option} #{File.expand_path(project.root).shellescape}" : nil - "#{project.tmux} new-window #{path} -t #{tmux_window_target} -n #{name}" - end - - def tmux_layout_command - "#{project.tmux} select-layout -t #{tmux_window_target} #{layout}" - end - - def tmux_select_first_pane - "#{project.tmux} select-pane -t #{tmux_window_target}.#{panes.first.index + project.base_index}" - end - end -end diff -r 107d94e009cc -r 67a6071afec7 pmuxinator.gemspec --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pmuxinator.gemspec Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,53 @@ +# coding: utf-8 +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "pmuxinator/version" + +Gem::Specification.new do |s| + s.name = "pmuxinator" + s.version = Pmuxinator::VERSION + s.authors = ["Allen Bargi"] + s.email = ["allen.bargi@gmail.com"] + s.description = %q{Create and manage complex tmux sessions easily.} + s.summary = %q{Create and manage complex tmux sessions easily.} + s.homepage = "https://github.com/aziz/pmuxinator" + s.license = "MIT" + + s.files = Dir["lib/**/*", "spec/**/*", "bin/*"] + s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.require_paths = ["lib"] + + s.post_install_message = %q{ + __________________________________________________________ + .......................................................... + + Thank you for installing pmuxinator. + + Make sure that you've set these variables in your ENV: + + $EDITOR, $SHELL + + You can run `pmuxinator doctor` to make sure everything is set. + Happy tmuxing with pmuxinator! + + .......................................................... + __________________________________________________________ + } + + s.required_rubygems_version = ">= 1.8.23" + + s.add_dependency "thor", "~> 0.19", ">= 0.15.0" + s.add_dependency "erubis" + + s.add_development_dependency "bundler", "~> 1.3" + s.add_development_dependency "rspec", "~> 3.0.0" + s.add_development_dependency "simplecov" + s.add_development_dependency "coveralls" + s.add_development_dependency "awesome_print" + s.add_development_dependency "pry" + s.add_development_dependency "pry-nav" + s.add_development_dependency "factory_girl" + s.add_development_dependency "transpec" +end + diff -r 107d94e009cc -r 67a6071afec7 spec/factories/projects.rb --- a/spec/factories/projects.rb Mon Jul 21 08:29:18 2014 +0900 +++ b/spec/factories/projects.rb Mon Jul 21 08:32:00 2014 +0900 @@ -1,25 +1,25 @@ FactoryGirl.define do - factory :project, :class => Tmuxinator::Project do + factory :project, :class => Pmuxinator::Project do ignore do file { YAML.load(File.read("#{File.expand_path("spec/fixtures/sample.yml")}")) } end - initialize_with { Tmuxinator::Project.new(file) } + initialize_with { Pmuxinator::Project.new(file) } end - factory :project_with_deprecations, :class => Tmuxinator::Project do + factory :project_with_deprecations, :class => Pmuxinator::Project do ignore do file { YAML.load(File.read("#{File.expand_path("spec/fixtures/sample.deprecations.yml")}")) } end - initialize_with { Tmuxinator::Project.new(file) } + initialize_with { Pmuxinator::Project.new(file) } end - factory :wemux_project, :class => Tmuxinator::Project do + factory :wemux_project, :class => Pmuxinator::Project do ignore do file { YAML.load(File.read("#{File.expand_path("spec/fixtures/sample_wemux.yml")}")) } end - initialize_with { Tmuxinator::Project.new(file) } + initialize_with { Pmuxinator::Project.new(file) } end end diff -r 107d94e009cc -r 67a6071afec7 spec/fixtures/sample.deprecations.yml --- a/spec/fixtures/sample.deprecations.yml Mon Jul 21 08:29:18 2014 +0900 +++ b/spec/fixtures/sample.deprecations.yml Mon Jul 21 08:32:00 2014 +0900 @@ -1,4 +1,4 @@ -# ~/.tmuxinator/sample.deprecations.yml +# ~/.pmuxinator/sample.deprecations.yml project_name: sample project_root: ~/test diff -r 107d94e009cc -r 67a6071afec7 spec/fixtures/sample.yml --- a/spec/fixtures/sample.yml Mon Jul 21 08:29:18 2014 +0900 +++ b/spec/fixtures/sample.yml Mon Jul 21 08:32:00 2014 +0900 @@ -1,4 +1,4 @@ -# ~/.tmuxinator/sample.yml +# ~/.pmuxinator/sample.yml # you can make as many tabs as you wish... name: sample diff -r 107d94e009cc -r 67a6071afec7 spec/fixtures/sample_wemux.yml --- a/spec/fixtures/sample_wemux.yml Mon Jul 21 08:29:18 2014 +0900 +++ b/spec/fixtures/sample_wemux.yml Mon Jul 21 08:32:00 2014 +0900 @@ -1,4 +1,4 @@ -# ~/.tmuxinator/sample_wemux.yml +# ~/.pmuxinator/sample_wemux.yml # you can make as many tabs as you wish... name: sample diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/cli_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/cli_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,231 @@ +require "spec_helper" +describe Pmuxinator::Cli do + let(:cli) { Pmuxinator::Cli } + + before do + ARGV.clear + allow(Kernel).to receive(:system) + allow(FileUtils).to receive(:copy_file) + allow(FileUtils).to receive(:rm) + allow(FileUtils).to receive(:remove_dir) + end + + context "no arguments" do + it "runs without error" do + _, err = capture_io { cli.start } + expect(err).to be_empty + end + end + + describe "#completions" do + before do + ARGV.replace(["completions", "start"]) + allow(Pmuxinator::Config).to receive_messages(:configs => ["test.yml"]) + end + + it "gets completions" do + out, _ = capture_io { cli.start } + expect(out).to include("test.yml") + end + end + + describe "#commands" do + before do + ARGV.replace(["commands"]) + end + + it "lists the commands" do + out, _ = capture_io { cli.start } + expect(out).to eq "#{%w(commands copy debug delete doctor help implode list start version).join("\n")}\n" + end + end + + describe "#start" do + before do + ARGV.replace(["start", "foo"]) + allow(Pmuxinator::Config).to receive_messages(:validate => project) + allow(Pmuxinator::Config).to receive_messages(:version => 1.9) + allow(Kernel).to receive(:exec) + end + + context "no deprecations" do + let(:project) { FactoryGirl.build(:project) } + + it "starts the project" do + expect(Kernel).to receive(:exec) + capture_io { cli.start } + end + end + + context "deprecations" do + before do + allow($stdin).to receive_messages(:getc => "y") + end + + let(:project) { FactoryGirl.build(:project_with_deprecations) } + + it "prints the deprecations" do + out, _ = capture_io { cli.start } + expect(out).to include "DEPRECATION" + end + end + end + + describe "#new" do + let(:file) { StringIO.new } + + before do + ARGV.replace(["new", "test"]) + allow(File).to receive(:open) { |&block| block.yield file } + end + + context "existing project doesn't exist" do + before do + allow(Pmuxinator::Config).to receive_messages(:exists? => false) + end + + it "creates a new pmuxinator project file" do + capture_io { cli.start } + expect(file.string).to_not be_empty + end + end + + context "files exists" do + before do + allow(File).to receive_messages(:exists? => true) + end + + it "just opens the file" do + expect(Kernel).to receive(:system) + capture_io { cli.start } + end + end + end + + describe "#copy" do + before do + ARGV.replace(["copy", "foo", "bar"]) + allow(Pmuxinator::Config).to receive(:exists?) { true } + end + + context "new project already exists" do + before do + allow(Thor::LineEditor).to receive_messages(:readline => "y") + end + + it "prompts user to confirm overwrite" do + expect(FileUtils).to receive(:rm) + capture_io { cli.start } + end + + it "copies the config" do + expect(FileUtils).to receive(:copy_file) + capture_io { cli.start } + end + end + + context "existing project doens't exist" do + before do + allow(Pmuxinator::Config).to receive(:exists?) { false } + end + + it "exit with error code" do + expect { capture_io { cli.start } }.to raise_error SystemExit + end + end + end + + describe "#debug" do + let(:project) { FactoryGirl.build(:project) } + + before do + ARGV.replace(["debug", "foo"]) + allow(Pmuxinator::Config).to receive_messages(:validate => project) + end + + it "renders the project" do + expect(project).to receive(:render) + capture_io { cli.start } + end + end + + describe "#delete" do + before do + ARGV.replace(["delete", "foo"]) + allow(Thor::LineEditor).to receive_messages(:readline => "y") + end + + context "project exists" do + before do + allow(Pmuxinator::Config).to receive(:exists?) { true } + end + + it "deletes the project" do + expect(FileUtils).to receive(:rm) + capture_io { cli.start } + end + end + + context "project doesn't exist" do + before do + allow(Thor::LineEditor).to receive_messages(:readline => "y") + end + + it "exits with error message" do + expect { capture_io { cli.start } }.to raise_error SystemExit + end + end + end + + describe "#implode" do + before do + ARGV.replace(["implode"]) + allow(Thor::LineEditor).to receive_messages(:readline => "y") + end + + it "confirms deletion of all projects" do + expect(Thor::LineEditor).to receive(:readline).and_return("y") + capture_io { cli.start } + end + + it "deletes all projects" do + expect(FileUtils).to receive(:remove_dir) + capture_io { cli.start } + end + end + + describe "#list" do + before do + ARGV.replace(["list"]) + allow(Dir).to receive_messages(:[] => ["/path/to/project.yml"]) + end + + it "lists all projects" do + expect { capture_io { cli.start } }.to_not raise_error + end + end + + describe "#version" do + before do + ARGV.replace(["version"]) + end + + it "prints the current version" do + out, _ = capture_io { cli.start } + expect(out).to eq "pmuxinator #{Pmuxinator::VERSION}\n" + end + end + + describe "#doctor" do + before do + ARGV.replace(["doctor"]) + end + + it "checks requirements" do + expect(Pmuxinator::Config).to receive(:installed?) + expect(Pmuxinator::Config).to receive(:editor?) + expect(Pmuxinator::Config).to receive(:shell?) + capture_io { cli.start } + end + end +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/config_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/config_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,153 @@ +require "spec_helper" + +describe Pmuxinator::Config do + describe "#root" do + it "is ~/.tmuxintaor" do + expect(Pmuxinator::Config.root).to eq "#{ENV["HOME"]}/.pmuxinator" + end + end + + describe "#sample" do + it "gets the path of the sample project" do + expect(Pmuxinator::Config.sample).to include("sample.yml") + end + end + + describe "#default" do + it "gets the path of the default config" do + expect(Pmuxinator::Config.default).to include("default.yml") + end + end + + describe "#default?" do + let(:root) { Pmuxinator::Config.root } + + context "when the file exists" do + before do + allow(File).to receive(:exists?).with(Pmuxinator::Config.default) { true } + end + + it "returns true" do + expect(Pmuxinator::Config.default?).to be_truthy + end + end + + context "when the file doesn't exist" do + before do + allow(File).to receive(:exists?).with(Pmuxinator::Config.default) { false } + end + + it "returns true" do + expect(Pmuxinator::Config.default?).to be_falsey + end + end + end + + describe "#configs" do + before do + allow(Dir).to receive_messages(:[] => ["test.yml"]) + end + + it "gets a list of all projects" do + expect(Pmuxinator::Config.configs).to include("test") + end + end + + describe "#installed?" do + context "tmux is installed" do + before do + allow(Kernel).to receive(:system) { true } + end + + it "returns true" do + expect(Pmuxinator::Config.installed?).to be_truthy + end + end + + context "tmux is not installed" do + before do + allow(Kernel).to receive(:system) { false } + end + + it "returns true" do + expect(Pmuxinator::Config.installed?).to be_falsey + end + end + end + + describe "#editor?" do + context "$EDITOR is set" do + before do + allow(ENV).to receive(:[]).with("EDITOR") { "vim" } + end + + it "returns true" do + expect(Pmuxinator::Config.editor?).to be_truthy + end + end + + context "$EDITOR is not set" do + before do + allow(ENV).to receive(:[]).with("EDITOR") { nil } + end + + it "returns false" do + expect(Pmuxinator::Config.editor?).to be_falsey + end + end + end + + describe "#shell?" do + context "$SHELL is set" do + before do + allow(ENV).to receive(:[]).with("SHELL") { "vim" } + end + + it "returns true" do + expect(Pmuxinator::Config.shell?).to be_truthy + end + end + + context "$SHELL is not set" do + before do + allow(ENV).to receive(:[]).with("SHELL") { nil } + end + + it "returns false" do + expect(Pmuxinator::Config.shell?).to be_falsey + end + end + end + + describe "#exists?" do + before do + allow(File).to receive_messages(:exists? => true) + allow(Pmuxinator::Config).to receive_messages(:project => "") + end + + it "checks if the given project exists" do + expect(Pmuxinator::Config.exists?("test")).to be_truthy + end + end + + describe "#project" do + let(:root) { Pmuxinator::Config.root } + + before do + path = File.expand_path("../../../fixtures/", __FILE__) + allow(Pmuxinator::Config).to receive_messages(:root => path) + end + + context "with project yml" do + it "gets the project as path to the yml file" do + expect(Pmuxinator::Config.project("sample")).to eq "#{root}/sample.yml" + end + end + + context "without project yml" do + it "gets the project as path to the yml file" do + expect(Pmuxinator::Config.project("new-project")).to eq "#{root}/new-project.yml" + end + end + end +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/pane_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/pane_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,7 @@ +require "spec_helper" + +describe Pmuxinator::Pane do + it "creates an instance" do + expect(Pmuxinator::Pane.new("vim", 0, nil, nil)).to be_a(Pmuxinator::Pane) + end +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/project_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/project_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,313 @@ +require "spec_helper" + +describe Pmuxinator::Project do + let(:project) { FactoryGirl.build(:project) } + let(:project_with_deprecations) { FactoryGirl.build(:project_with_deprecations) } + let(:wemux_project) { FactoryGirl.build(:wemux_project) } + + describe "#initialize" do + context "valid yaml" do + it "creates an instance" do + expect(project).to be_a(Pmuxinator::Project) + end + end + end + + describe "#render" do + it "renders the tmux config" do + expect(project.render).to_not be_empty + end + + context "wemux" do + it "renders the wemux config" do + expect(wemux_project.render).to_not be_empty + end + end + end + + describe "#windows" do + context "without deprecations" do + it "gets the list of windows" do + expect(project.windows).to_not be_empty + end + end + + context "with deprecations" do + it "still gets the list of windows" do + expect(project_with_deprecations.windows).to_not be_empty + end + end + end + + describe "#root" do + context "without deprecations" do + it "gets the root" do + expect(project.root).to include("test") + end + end + + context "with deprecations" do + it "still gets the root" do + expect(project_with_deprecations.root).to include("test") + end + end + end + + describe "#name" do + context "without deprecations" do + it "gets the name" do + expect(project.name).to eq "sample" + end + end + + context "with deprecations" do + it "still gets the name" do + expect(project_with_deprecations.name).to eq "sample" + end + end + + context "wemux" do + it "is wemux" do + expect(wemux_project.name).to eq "wemux" + end + end + end + + describe "#pre_window" do + it "gets the pre_window command" do + expect(project.pre_window).to eq "rbenv shell 2.0.0-p247" + end + + context "with deprecations" do + context "rbenv option is present" do + before do + allow(project).to receive_messages(:rbenv? => true) + allow(project).to receive_message_chain(:yaml, :[]).and_return("2.0.0-p247") + end + + it "still gets the correct pre_window command" do + expect(project.pre_window).to eq "rbenv shell 2.0.0-p247" + end + end + + context "rvm option is present" do + before do + allow(project).to receive_messages(:rbenv? => false) + allow(project).to receive_message_chain(:yaml, :[]).and_return("ruby-2.0.0-p247") + end + + it "still gets the correct pre_window command" do + expect(project.pre_window).to eq "rvm use ruby-2.0.0-p247" + end + end + + context "pre_tab is present" do + before do + allow(project).to receive_messages(:rbenv? => false) + allow(project).to receive_messages(:pre_tab? => true) + end + + it "still gets the correct pre_window command" do + expect(project.pre_window).to be_nil + end + end + end + end + + describe "#socket" do + context "socket path is present" do + before do + allow(project).to receive_messages(:socket_path => "/tmp") + end + + it "gets the socket path" do + expect(project.socket).to eq " -S /tmp" + end + end + end + + describe "#tmux_command" do + context "tmux_command specified" do + before do + project.yaml["tmux_command"] = "byobu" + end + + it "gets the custom tmux command" do + expect(project.tmux_command).to eq "byobu" + end + end + + context "tmux_command is not specified" do + it "returns the default" do + expect(project.tmux_command).to eq "tmux" + end + end + end + + describe "#tmux_options" do + context "no tmux options" do + before do + allow(project).to receive_messages(:tmux_options? => false) + end + + it "returns nothing" do + expect(project.tmux_options).to eq "" + end + end + + context "with deprecations" do + before do + allow(project_with_deprecations).to receive_messages(:cli_args? => true) + end + + it "still gets the tmux options" do + expect(project_with_deprecations.tmux_options).to eq " -f ~/.tmux.mac.conf" + end + end + end + + describe "#get_pane_base_index" do + it "extracts the pane_base_index from tmux_options" do + allow(project).to receive_messages(show_tmux_options: tmux_config(pane_base_index: 3)) + + expect(project.get_pane_base_index).to eq("3") + end + end + + describe "#get_base_index" do + it "extracts the base index from options" do + allow(project).to receive_messages(show_tmux_options: tmux_config(base_index: 1)) + + expect(project.get_base_index).to eq("1") + end + end + + describe "#base_index" do + context "pane base index present" do + before do + allow(project).to receive_messages(:get_pane_base_index => "1") + allow(project).to receive_messages(:get_base_index => "1") + end + + it "gets the pane base index" do + expect(project.base_index).to eq 1 + end + end + + context "pane base index no present" do + before do + allow(project).to receive_messages(:get_pane_base_index => nil) + allow(project).to receive_messages(:get_base_index => "0") + end + + it "gets the base index" do + expect(project.base_index).to eq 0 + end + end + end + + describe "#window" do + it "gets the window and index for tmux" do + expect(project.window(1)).to eq "sample:1" + end + end + + describe "#name?" do + context "name is present" do + it "returns true" do + expect(project.name?).to be_truthy + end + end + end + + describe "#windows?" do + context "windows are present" do + it "returns true" do + expect(project.windows?).to be_truthy + end + end + end + + describe "#root?" do + context "root are present" do + it "returns true" do + expect(project.root?).to be_truthy + end + end + end + + describe "#send_keys" do + context "no command for window" do + it "returns empty string" do + expect(project.send_keys("", 1)).to be_empty + end + end + + context "command for window is not empty" do + it "returns the tmux command" do + expect(project.send_keys("vim", 1)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m" + end + end + end + + describe "#send_pane_command" do + context "no command for pane" do + it "returns empty string" do + expect(project.send_pane_command("", 0, 0)).to be_empty + end + end + + context "command for pane is not empty" do + it "returns the tmux command" do + expect(project.send_pane_command("vim", 1, 0)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m" + end + end + end + + describe "#deprecations" do + context "without deprecations" do + it "is empty" do + expect(project.deprecations).to be_empty + end + end + + context "with deprecations" do + it "is not empty" do + expect(project_with_deprecations.deprecations).to_not be_empty + end + end + end + + describe "#commands" do + let(:window) { project.windows.keep_if { |w| w.name == "shell" }.first } + + it "splits commands into an array" do + expect(window.commands).to eq(["tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ pull C-m", "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ merge C-m"]) + end + end + + describe "#pre" do + subject(:pre) { project.pre } + + context "pre in yaml is string" do + before { project.yaml["pre"] = "mysql.server start" } + + it "returns the string" do + expect(pre).to eq("mysql.server start") + end + end + + context "pre in yaml is Array" do + before { + project.yaml["pre"] = [ + "mysql.server start", + "memcached -d" + ] + } + + it "joins array using ;" do + expect(pre).to eq("mysql.server start; memcached -d") + end + end + end +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/util_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/util_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,6 @@ +require "spec_helper" + +describe Pmuxinator::Util do + let(:util) { Object.new.extend(Pmuxinator::Util) } + +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/pmuxinator/window_spec.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/lib/pmuxinator/window_spec.rb Mon Jul 21 08:32:00 2014 +0900 @@ -0,0 +1,154 @@ +require "spec_helper" + +describe Pmuxinator::Window do + let(:project) { double } + let(:panes) { ["vim", nil, "top"] } + let(:yaml) do + { + "editor" => { + "pre" => ["echo 'I get run in each pane. Before each pane command!'", nil], + "layout" => "main-vertical", + "panes" => panes + } + } + end + + let(:window) { Pmuxinator::Window.new(yaml, 0, project) } + + before do + allow(project).to receive_messages(:tmux => "tmux", :name => "test", :base_index => 1) + end + + describe "#initialize" do + it "creates an instance" do + expect(window).to be_a(Pmuxinator::Window) + end + end + + describe "#panes" do + let(:pane) { double(:pane) } + + before do + allow(Pmuxinator::Pane).to receive_messages :new => pane + end + + context "with a three element Array" do + let(:panes) { ["vim", nil, "top"] } + + it "creates three panes" do + expect(Pmuxinator::Pane).to receive(:new).exactly(3).times + window.panes + end + + it "returns three panes" do + expect(window.panes).to eql [pane, pane, pane] + end + end + + context "with a String" do + let(:panes) { "vim" } + + it "creates one pane" do + expect(Pmuxinator::Pane).to receive(:new).once + window.panes + end + + it "returns one pane in an Array" do + expect(window.panes).to eql [pane] + end + end + + context "with nil" do + let(:panes) { nil } + + it "doesn't create any panes" do + expect(Pmuxinator::Pane).to_not receive(:new) + window.panes + end + + it "returns an empty Array" do + expect(window.panes).to be_empty + end + end + end + + describe "#pre" do + context "pre is a string" do + before do + yaml["editor"]["pre"] = "vim" + end + + it "returns the pre command" do + expect(window.pre).to eq "vim" + end + end + + + context "pre is not present" do + before do + yaml["editor"].delete("pre") + end + + it "returns an empty string" do + expect(window.pre).to eq "" + end + end + end + + describe "#build_commands" do + context "command is an array" do + before do + yaml["editor"] = ["git fetch", "git status"] + end + + it "returns the flattened command" do + expect(window.commands).to eq ["tmux send-keys -t test:1 git\\ fetch C-m", "tmux send-keys -t test:1 git\\ status C-m"] + end + end + + context "command is a string" do + before do + yaml["editor"] = "vim" + end + + it "returns the command" do + expect(window.commands).to eq ["tmux send-keys -t test:1 vim C-m"] + end + end + + context "command is empty" do + before do + yaml["editor"] = "" + end + + it "returns an empty array" do + expect(window.commands).to be_empty + end + end + end + + describe "#tmux_new_window_command" do + let(:project) { double(:project) } + let(:window) { Pmuxinator::Window.new(yaml, 0, project) } + + before do + allow(project).to receive_messages( + :name => "", + :tmux => "tmux", + :root => "/project/pmuxinator", + :root? => true, + :base_index => 1 + ) + end + + context "tmux 1.6 and below" do + before do + allow(Pmuxinator::Config).to receive_messages(:version => 1.6) + end + + it "specifies root path by passing default-path to tmux" do + expect(window.tmux_new_window_command).to include("default-path /project/pmuxinator") + end + end + end +end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/cli_spec.rb --- a/spec/lib/tmuxinator/cli_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +0,0 @@ -require "spec_helper" -describe Tmuxinator::Cli do - let(:cli) { Tmuxinator::Cli } - - before do - ARGV.clear - allow(Kernel).to receive(:system) - allow(FileUtils).to receive(:copy_file) - allow(FileUtils).to receive(:rm) - allow(FileUtils).to receive(:remove_dir) - end - - context "no arguments" do - it "runs without error" do - _, err = capture_io { cli.start } - expect(err).to be_empty - end - end - - describe "#completions" do - before do - ARGV.replace(["completions", "start"]) - allow(Tmuxinator::Config).to receive_messages(:configs => ["test.yml"]) - end - - it "gets completions" do - out, _ = capture_io { cli.start } - expect(out).to include("test.yml") - end - end - - describe "#commands" do - before do - ARGV.replace(["commands"]) - end - - it "lists the commands" do - out, _ = capture_io { cli.start } - expect(out).to eq "#{%w(commands copy debug delete doctor help implode list start version).join("\n")}\n" - end - end - - describe "#start" do - before do - ARGV.replace(["start", "foo"]) - allow(Tmuxinator::Config).to receive_messages(:validate => project) - allow(Tmuxinator::Config).to receive_messages(:version => 1.9) - allow(Kernel).to receive(:exec) - end - - context "no deprecations" do - let(:project) { FactoryGirl.build(:project) } - - it "starts the project" do - expect(Kernel).to receive(:exec) - capture_io { cli.start } - end - end - - context "deprecations" do - before do - allow($stdin).to receive_messages(:getc => "y") - end - - let(:project) { FactoryGirl.build(:project_with_deprecations) } - - it "prints the deprecations" do - out, _ = capture_io { cli.start } - expect(out).to include "DEPRECATION" - end - end - end - - describe "#new" do - let(:file) { StringIO.new } - - before do - ARGV.replace(["new", "test"]) - allow(File).to receive(:open) { |&block| block.yield file } - end - - context "existing project doesn't exist" do - before do - allow(Tmuxinator::Config).to receive_messages(:exists? => false) - end - - it "creates a new tmuxinator project file" do - capture_io { cli.start } - expect(file.string).to_not be_empty - end - end - - context "files exists" do - before do - allow(File).to receive_messages(:exists? => true) - end - - it "just opens the file" do - expect(Kernel).to receive(:system) - capture_io { cli.start } - end - end - end - - describe "#copy" do - before do - ARGV.replace(["copy", "foo", "bar"]) - allow(Tmuxinator::Config).to receive(:exists?) { true } - end - - context "new project already exists" do - before do - allow(Thor::LineEditor).to receive_messages(:readline => "y") - end - - it "prompts user to confirm overwrite" do - expect(FileUtils).to receive(:rm) - capture_io { cli.start } - end - - it "copies the config" do - expect(FileUtils).to receive(:copy_file) - capture_io { cli.start } - end - end - - context "existing project doens't exist" do - before do - allow(Tmuxinator::Config).to receive(:exists?) { false } - end - - it "exit with error code" do - expect { capture_io { cli.start } }.to raise_error SystemExit - end - end - end - - describe "#debug" do - let(:project) { FactoryGirl.build(:project) } - - before do - ARGV.replace(["debug", "foo"]) - allow(Tmuxinator::Config).to receive_messages(:validate => project) - end - - it "renders the project" do - expect(project).to receive(:render) - capture_io { cli.start } - end - end - - describe "#delete" do - before do - ARGV.replace(["delete", "foo"]) - allow(Thor::LineEditor).to receive_messages(:readline => "y") - end - - context "project exists" do - before do - allow(Tmuxinator::Config).to receive(:exists?) { true } - end - - it "deletes the project" do - expect(FileUtils).to receive(:rm) - capture_io { cli.start } - end - end - - context "project doesn't exist" do - before do - allow(Thor::LineEditor).to receive_messages(:readline => "y") - end - - it "exits with error message" do - expect { capture_io { cli.start } }.to raise_error SystemExit - end - end - end - - describe "#implode" do - before do - ARGV.replace(["implode"]) - allow(Thor::LineEditor).to receive_messages(:readline => "y") - end - - it "confirms deletion of all projects" do - expect(Thor::LineEditor).to receive(:readline).and_return("y") - capture_io { cli.start } - end - - it "deletes all projects" do - expect(FileUtils).to receive(:remove_dir) - capture_io { cli.start } - end - end - - describe "#list" do - before do - ARGV.replace(["list"]) - allow(Dir).to receive_messages(:[] => ["/path/to/project.yml"]) - end - - it "lists all projects" do - expect { capture_io { cli.start } }.to_not raise_error - end - end - - describe "#version" do - before do - ARGV.replace(["version"]) - end - - it "prints the current version" do - out, _ = capture_io { cli.start } - expect(out).to eq "tmuxinator #{Tmuxinator::VERSION}\n" - end - end - - describe "#doctor" do - before do - ARGV.replace(["doctor"]) - end - - it "checks requirements" do - expect(Tmuxinator::Config).to receive(:installed?) - expect(Tmuxinator::Config).to receive(:editor?) - expect(Tmuxinator::Config).to receive(:shell?) - capture_io { cli.start } - end - end -end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/config_spec.rb --- a/spec/lib/tmuxinator/config_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -require "spec_helper" - -describe Tmuxinator::Config do - describe "#root" do - it "is ~/.tmuxintaor" do - expect(Tmuxinator::Config.root).to eq "#{ENV["HOME"]}/.tmuxinator" - end - end - - describe "#sample" do - it "gets the path of the sample project" do - expect(Tmuxinator::Config.sample).to include("sample.yml") - end - end - - describe "#default" do - it "gets the path of the default config" do - expect(Tmuxinator::Config.default).to include("default.yml") - end - end - - describe "#default?" do - let(:root) { Tmuxinator::Config.root } - - context "when the file exists" do - before do - allow(File).to receive(:exists?).with(Tmuxinator::Config.default) { true } - end - - it "returns true" do - expect(Tmuxinator::Config.default?).to be_truthy - end - end - - context "when the file doesn't exist" do - before do - allow(File).to receive(:exists?).with(Tmuxinator::Config.default) { false } - end - - it "returns true" do - expect(Tmuxinator::Config.default?).to be_falsey - end - end - end - - describe "#configs" do - before do - allow(Dir).to receive_messages(:[] => ["test.yml"]) - end - - it "gets a list of all projects" do - expect(Tmuxinator::Config.configs).to include("test") - end - end - - describe "#installed?" do - context "tmux is installed" do - before do - allow(Kernel).to receive(:system) { true } - end - - it "returns true" do - expect(Tmuxinator::Config.installed?).to be_truthy - end - end - - context "tmux is not installed" do - before do - allow(Kernel).to receive(:system) { false } - end - - it "returns true" do - expect(Tmuxinator::Config.installed?).to be_falsey - end - end - end - - describe "#editor?" do - context "$EDITOR is set" do - before do - allow(ENV).to receive(:[]).with("EDITOR") { "vim" } - end - - it "returns true" do - expect(Tmuxinator::Config.editor?).to be_truthy - end - end - - context "$EDITOR is not set" do - before do - allow(ENV).to receive(:[]).with("EDITOR") { nil } - end - - it "returns false" do - expect(Tmuxinator::Config.editor?).to be_falsey - end - end - end - - describe "#shell?" do - context "$SHELL is set" do - before do - allow(ENV).to receive(:[]).with("SHELL") { "vim" } - end - - it "returns true" do - expect(Tmuxinator::Config.shell?).to be_truthy - end - end - - context "$SHELL is not set" do - before do - allow(ENV).to receive(:[]).with("SHELL") { nil } - end - - it "returns false" do - expect(Tmuxinator::Config.shell?).to be_falsey - end - end - end - - describe "#exists?" do - before do - allow(File).to receive_messages(:exists? => true) - allow(Tmuxinator::Config).to receive_messages(:project => "") - end - - it "checks if the given project exists" do - expect(Tmuxinator::Config.exists?("test")).to be_truthy - end - end - - describe "#project" do - let(:root) { Tmuxinator::Config.root } - - before do - path = File.expand_path("../../../fixtures/", __FILE__) - allow(Tmuxinator::Config).to receive_messages(:root => path) - end - - context "with project yml" do - it "gets the project as path to the yml file" do - expect(Tmuxinator::Config.project("sample")).to eq "#{root}/sample.yml" - end - end - - context "without project yml" do - it "gets the project as path to the yml file" do - expect(Tmuxinator::Config.project("new-project")).to eq "#{root}/new-project.yml" - end - end - end -end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/pane_spec.rb --- a/spec/lib/tmuxinator/pane_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -require "spec_helper" - -describe Tmuxinator::Pane do - it "creates an instance" do - expect(Tmuxinator::Pane.new("vim", 0, nil, nil)).to be_a(Tmuxinator::Pane) - end -end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/project_spec.rb --- a/spec/lib/tmuxinator/project_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,313 +0,0 @@ -require "spec_helper" - -describe Tmuxinator::Project do - let(:project) { FactoryGirl.build(:project) } - let(:project_with_deprecations) { FactoryGirl.build(:project_with_deprecations) } - let(:wemux_project) { FactoryGirl.build(:wemux_project) } - - describe "#initialize" do - context "valid yaml" do - it "creates an instance" do - expect(project).to be_a(Tmuxinator::Project) - end - end - end - - describe "#render" do - it "renders the tmux config" do - expect(project.render).to_not be_empty - end - - context "wemux" do - it "renders the wemux config" do - expect(wemux_project.render).to_not be_empty - end - end - end - - describe "#windows" do - context "without deprecations" do - it "gets the list of windows" do - expect(project.windows).to_not be_empty - end - end - - context "with deprecations" do - it "still gets the list of windows" do - expect(project_with_deprecations.windows).to_not be_empty - end - end - end - - describe "#root" do - context "without deprecations" do - it "gets the root" do - expect(project.root).to include("test") - end - end - - context "with deprecations" do - it "still gets the root" do - expect(project_with_deprecations.root).to include("test") - end - end - end - - describe "#name" do - context "without deprecations" do - it "gets the name" do - expect(project.name).to eq "sample" - end - end - - context "with deprecations" do - it "still gets the name" do - expect(project_with_deprecations.name).to eq "sample" - end - end - - context "wemux" do - it "is wemux" do - expect(wemux_project.name).to eq "wemux" - end - end - end - - describe "#pre_window" do - it "gets the pre_window command" do - expect(project.pre_window).to eq "rbenv shell 2.0.0-p247" - end - - context "with deprecations" do - context "rbenv option is present" do - before do - allow(project).to receive_messages(:rbenv? => true) - allow(project).to receive_message_chain(:yaml, :[]).and_return("2.0.0-p247") - end - - it "still gets the correct pre_window command" do - expect(project.pre_window).to eq "rbenv shell 2.0.0-p247" - end - end - - context "rvm option is present" do - before do - allow(project).to receive_messages(:rbenv? => false) - allow(project).to receive_message_chain(:yaml, :[]).and_return("ruby-2.0.0-p247") - end - - it "still gets the correct pre_window command" do - expect(project.pre_window).to eq "rvm use ruby-2.0.0-p247" - end - end - - context "pre_tab is present" do - before do - allow(project).to receive_messages(:rbenv? => false) - allow(project).to receive_messages(:pre_tab? => true) - end - - it "still gets the correct pre_window command" do - expect(project.pre_window).to be_nil - end - end - end - end - - describe "#socket" do - context "socket path is present" do - before do - allow(project).to receive_messages(:socket_path => "/tmp") - end - - it "gets the socket path" do - expect(project.socket).to eq " -S /tmp" - end - end - end - - describe "#tmux_command" do - context "tmux_command specified" do - before do - project.yaml["tmux_command"] = "byobu" - end - - it "gets the custom tmux command" do - expect(project.tmux_command).to eq "byobu" - end - end - - context "tmux_command is not specified" do - it "returns the default" do - expect(project.tmux_command).to eq "tmux" - end - end - end - - describe "#tmux_options" do - context "no tmux options" do - before do - allow(project).to receive_messages(:tmux_options? => false) - end - - it "returns nothing" do - expect(project.tmux_options).to eq "" - end - end - - context "with deprecations" do - before do - allow(project_with_deprecations).to receive_messages(:cli_args? => true) - end - - it "still gets the tmux options" do - expect(project_with_deprecations.tmux_options).to eq " -f ~/.tmux.mac.conf" - end - end - end - - describe "#get_pane_base_index" do - it "extracts the pane_base_index from tmux_options" do - allow(project).to receive_messages(show_tmux_options: tmux_config(pane_base_index: 3)) - - expect(project.get_pane_base_index).to eq("3") - end - end - - describe "#get_base_index" do - it "extracts the base index from options" do - allow(project).to receive_messages(show_tmux_options: tmux_config(base_index: 1)) - - expect(project.get_base_index).to eq("1") - end - end - - describe "#base_index" do - context "pane base index present" do - before do - allow(project).to receive_messages(:get_pane_base_index => "1") - allow(project).to receive_messages(:get_base_index => "1") - end - - it "gets the pane base index" do - expect(project.base_index).to eq 1 - end - end - - context "pane base index no present" do - before do - allow(project).to receive_messages(:get_pane_base_index => nil) - allow(project).to receive_messages(:get_base_index => "0") - end - - it "gets the base index" do - expect(project.base_index).to eq 0 - end - end - end - - describe "#window" do - it "gets the window and index for tmux" do - expect(project.window(1)).to eq "sample:1" - end - end - - describe "#name?" do - context "name is present" do - it "returns true" do - expect(project.name?).to be_truthy - end - end - end - - describe "#windows?" do - context "windows are present" do - it "returns true" do - expect(project.windows?).to be_truthy - end - end - end - - describe "#root?" do - context "root are present" do - it "returns true" do - expect(project.root?).to be_truthy - end - end - end - - describe "#send_keys" do - context "no command for window" do - it "returns empty string" do - expect(project.send_keys("", 1)).to be_empty - end - end - - context "command for window is not empty" do - it "returns the tmux command" do - expect(project.send_keys("vim", 1)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m" - end - end - end - - describe "#send_pane_command" do - context "no command for pane" do - it "returns empty string" do - expect(project.send_pane_command("", 0, 0)).to be_empty - end - end - - context "command for pane is not empty" do - it "returns the tmux command" do - expect(project.send_pane_command("vim", 1, 0)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m" - end - end - end - - describe "#deprecations" do - context "without deprecations" do - it "is empty" do - expect(project.deprecations).to be_empty - end - end - - context "with deprecations" do - it "is not empty" do - expect(project_with_deprecations.deprecations).to_not be_empty - end - end - end - - describe "#commands" do - let(:window) { project.windows.keep_if { |w| w.name == "shell" }.first } - - it "splits commands into an array" do - expect(window.commands).to eq(["tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ pull C-m", "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ merge C-m"]) - end - end - - describe "#pre" do - subject(:pre) { project.pre } - - context "pre in yaml is string" do - before { project.yaml["pre"] = "mysql.server start" } - - it "returns the string" do - expect(pre).to eq("mysql.server start") - end - end - - context "pre in yaml is Array" do - before { - project.yaml["pre"] = [ - "mysql.server start", - "memcached -d" - ] - } - - it "joins array using ;" do - expect(pre).to eq("mysql.server start; memcached -d") - end - end - end -end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/util_spec.rb --- a/spec/lib/tmuxinator/util_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -require "spec_helper" - -describe Tmuxinator::Util do - let(:util) { Object.new.extend(Tmuxinator::Util) } - -end diff -r 107d94e009cc -r 67a6071afec7 spec/lib/tmuxinator/window_spec.rb --- a/spec/lib/tmuxinator/window_spec.rb Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -require "spec_helper" - -describe Tmuxinator::Window do - let(:project) { double } - let(:panes) { ["vim", nil, "top"] } - let(:yaml) do - { - "editor" => { - "pre" => ["echo 'I get run in each pane. Before each pane command!'", nil], - "layout" => "main-vertical", - "panes" => panes - } - } - end - - let(:window) { Tmuxinator::Window.new(yaml, 0, project) } - - before do - allow(project).to receive_messages(:tmux => "tmux", :name => "test", :base_index => 1) - end - - describe "#initialize" do - it "creates an instance" do - expect(window).to be_a(Tmuxinator::Window) - end - end - - describe "#panes" do - let(:pane) { double(:pane) } - - before do - allow(Tmuxinator::Pane).to receive_messages :new => pane - end - - context "with a three element Array" do - let(:panes) { ["vim", nil, "top"] } - - it "creates three panes" do - expect(Tmuxinator::Pane).to receive(:new).exactly(3).times - window.panes - end - - it "returns three panes" do - expect(window.panes).to eql [pane, pane, pane] - end - end - - context "with a String" do - let(:panes) { "vim" } - - it "creates one pane" do - expect(Tmuxinator::Pane).to receive(:new).once - window.panes - end - - it "returns one pane in an Array" do - expect(window.panes).to eql [pane] - end - end - - context "with nil" do - let(:panes) { nil } - - it "doesn't create any panes" do - expect(Tmuxinator::Pane).to_not receive(:new) - window.panes - end - - it "returns an empty Array" do - expect(window.panes).to be_empty - end - end - end - - describe "#pre" do - context "pre is a string" do - before do - yaml["editor"]["pre"] = "vim" - end - - it "returns the pre command" do - expect(window.pre).to eq "vim" - end - end - - - context "pre is not present" do - before do - yaml["editor"].delete("pre") - end - - it "returns an empty string" do - expect(window.pre).to eq "" - end - end - end - - describe "#build_commands" do - context "command is an array" do - before do - yaml["editor"] = ["git fetch", "git status"] - end - - it "returns the flattened command" do - expect(window.commands).to eq ["tmux send-keys -t test:1 git\\ fetch C-m", "tmux send-keys -t test:1 git\\ status C-m"] - end - end - - context "command is a string" do - before do - yaml["editor"] = "vim" - end - - it "returns the command" do - expect(window.commands).to eq ["tmux send-keys -t test:1 vim C-m"] - end - end - - context "command is empty" do - before do - yaml["editor"] = "" - end - - it "returns an empty array" do - expect(window.commands).to be_empty - end - end - end - - describe "#tmux_new_window_command" do - let(:project) { double(:project) } - let(:window) { Tmuxinator::Window.new(yaml, 0, project) } - - before do - allow(project).to receive_messages( - :name => "", - :tmux => "tmux", - :root => "/project/tmuxinator", - :root? => true, - :base_index => 1 - ) - end - - context "tmux 1.6 and below" do - before do - allow(Tmuxinator::Config).to receive_messages(:version => 1.6) - end - - it "specifies root path by passing default-path to tmux" do - expect(window.tmux_new_window_command).to include("default-path /project/tmuxinator") - end - end - end -end diff -r 107d94e009cc -r 67a6071afec7 spec/spec_helper.rb --- a/spec/spec_helper.rb Mon Jul 21 08:29:18 2014 +0900 +++ b/spec/spec_helper.rb Mon Jul 21 08:32:00 2014 +0900 @@ -10,7 +10,7 @@ add_filter 'vendor/cache' end -require "tmuxinator" +require "pmuxinator" require "factory_girl" diff -r 107d94e009cc -r 67a6071afec7 tmuxinator.gemspec --- a/tmuxinator.gemspec Mon Jul 21 08:29:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -# coding: utf-8 -lib = File.expand_path("../lib", __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "tmuxinator/version" - -Gem::Specification.new do |s| - s.name = "tmuxinator" - s.version = Tmuxinator::VERSION - s.authors = ["Allen Bargi"] - s.email = ["allen.bargi@gmail.com"] - s.description = %q{Create and manage complex tmux sessions easily.} - s.summary = %q{Create and manage complex tmux sessions easily.} - s.homepage = "https://github.com/aziz/tmuxinator" - s.license = "MIT" - - s.files = Dir["lib/**/*", "spec/**/*", "bin/*"] - s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } - s.test_files = s.files.grep(%r{^(test|spec|features)/}) - s.require_paths = ["lib"] - - s.post_install_message = %q{ - __________________________________________________________ - .......................................................... - - Thank you for installing tmuxinator. - - Make sure that you've set these variables in your ENV: - - $EDITOR, $SHELL - - You can run `tmuxinator doctor` to make sure everything is set. - Happy tmuxing with tmuxinator! - - .......................................................... - __________________________________________________________ - } - - s.required_rubygems_version = ">= 1.8.23" - - s.add_dependency "thor", "~> 0.19", ">= 0.15.0" - s.add_dependency "erubis" - - s.add_development_dependency "bundler", "~> 1.3" - s.add_development_dependency "rspec", "~> 3.0.0" - s.add_development_dependency "simplecov" - s.add_development_dependency "coveralls" - s.add_development_dependency "awesome_print" - s.add_development_dependency "pry" - s.add_development_dependency "pry-nav" - s.add_development_dependency "factory_girl" - s.add_development_dependency "transpec" -end -