Skip to content

Commit

Permalink
Add option "tmux_detached" for detach client
Browse files Browse the repository at this point in the history
This option specifies if tmux start with attached or detached state.
Start attached when "false" or option not defined, otherwise detached.
  • Loading branch information
mvaraga committed Feb 13, 2015
1 parent d081b6d commit 5bb43ca
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/tmuxinator/assets/sample.yml
Expand Up @@ -21,6 +21,9 @@ root: ~/
# Specifies (by name or index) which window will be selected on project startup. If not set, the first window is used.
# startup_window: logs

# for option to start detached
# tmux_detached: true

windows:
- editor:
layout: main-vertical
Expand Down
2 changes: 2 additions & 0 deletions lib/tmuxinator/assets/template.erb
Expand Up @@ -60,8 +60,10 @@ if [ "$?" -eq 1 ]; then
<%= tmux %> select-window -t <%= startup_window %>
fi

<% unless detached? %>
if [ -z "$TMUX" ]; then
<%= tmux %> -u attach-session -t <%= name %>
else
<%= tmux %> -u switch-client -t <%= name %>
fi
<%- end -%>
4 changes: 4 additions & 0 deletions lib/tmuxinator/project.rb
Expand Up @@ -43,6 +43,10 @@ def pre
end
end

def detached?
yaml["tmux_detached"]
end

def pre_window
if rbenv?
"rbenv shell #{yaml["rbenv"]}"
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/sample.yml
Expand Up @@ -7,6 +7,7 @@ socket_name: foo # Remove to use default socket
pre: sudo /etc/rc.d/mysqld start # Runs before everything
pre_window: rbenv shell 2.0.0-p247 # Runs in each tab and pane
tmux_options: -f ~/.tmux.mac.conf # Pass arguments to tmux
tmux_detached: false
windows:
- editor:
pre:
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/tmuxinator/project_spec.rb
Expand Up @@ -328,4 +328,29 @@
end
end
end

describe "#detached?" do
subject(:detached) { project.detached? }

context "tmux_detached is true in yaml" do
before { project.yaml["tmux_detached"] = true }

it "returns true" do
expect(detached).to be_truthy
end
end

context "tmux_detached is not defined in yaml" do
it "returns false" do
expect(detached).to be_falsey
end
end

context "tmux_detached is false in yaml" do
it "returns false" do
expect(detached).to be_falsey
end
end

end
end

0 comments on commit 5bb43ca

Please sign in to comment.