Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set pane title if provided in config file #891

Merged
merged 10 commits into from
Feb 8, 2024
3 changes: 3 additions & 0 deletions lib/tmuxinator/assets/template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ cd <%= root || "." %>
<% end %>
<% else %>
<% window.panes.each do |pane| %>
<% unless pane.title.nil? %>
<%= pane.tmux_set_title %>
<% end %>
<% if pane.project.pre_window %>
<%= pane.tmux_pre_window_command %>
<% end %>
Expand Down
16 changes: 14 additions & 2 deletions lib/tmuxinator/pane.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module Tmuxinator
class Pane
attr_reader :commands, :project, :index, :tab
attr_reader :commands, :project, :index, :tab, :title

def initialize(index, project, tab, *commands)
def initialize(index, project, tab, *commands, title: nil)
@commands = commands
@index = index
@project = project
@tab = tab
@title = title
end

def tmux_window_and_pane_target
Expand All @@ -29,6 +30,12 @@ def tmux_main_command(command)
end
end

def tmux_set_title
unless title.nil?
_set_title(title)
end
end

def name
project.name
end
Expand Down Expand Up @@ -61,5 +68,10 @@ def _send_target(e)
def _send_keys(t, e)
"#{project.tmux} send-keys -t #{t} #{e} C-m"
end

def _set_title(title)
target = tmux_window_and_pane_target
"#{project.tmux} select-pane -t #{target} -T #{title}"
end
end
end
20 changes: 10 additions & 10 deletions lib/tmuxinator/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def build_panes(panes_yml)
return if panes_yml.nil?

Array(panes_yml).map.with_index do |pane_yml, index|
commands = case pane_yml
when Hash
pane_yml.values.first
when Array
pane_yml
else
pane_yml
end

Tmuxinator::Pane.new(index, project, self, *commands)
commands, title = case pane_yml
when Hash
[pane_yml.values.first, pane_yml.keys.first]
when Array
[pane_yml, nil]
else
[pane_yml, nil]
end

Tmuxinator::Pane.new(index, project, self, *commands, title: title)
end.flatten
end

Expand Down