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

Add base index variables for panes and windows #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn convert_config_to_tmux_commands(config: &Config) -> Vec<Vec<String>> {

let session_start_directory = build_session_start_directory(&config);

let first_window = if let Some(window) = config.windows.get(0) {
let first_window = if let Some(window) = config.windows.first() {
window.name.clone()
} else {
None
Expand All @@ -230,7 +230,15 @@ fn convert_config_to_tmux_commands(config: &Config) -> Vec<Vec<String>> {
commands.push(hook_command);
}

for (window_index, window) in config.windows.iter().enumerate() {
// TODO Read from tmux config
let base_index = 0;
// TODO Read from tmux config
let pane_base_index = 0;

for (i, window) in config.windows.iter().enumerate() {

let window_index = base_index + i;

// The first window is created by create_session because tmux always
// creates a window when creating a session.
// The alternative would be to create all of the project windows and
Expand All @@ -239,7 +247,7 @@ fn convert_config_to_tmux_commands(config: &Config) -> Vec<Vec<String>> {
// think it's because the indexes get shuffled.
// The alternative approach would be more explicit and preferable, so
// maybe it's worth revisiting.
if window_index != 0 {
if window_index != base_index {
// TODO: This is heavy handed and this logic is _sort of_ duped
// in a few places. Maybe each type should have a method which is
// able to compute its own starting directory?
Expand All @@ -255,9 +263,13 @@ fn convert_config_to_tmux_commands(config: &Config) -> Vec<Vec<String>> {
commands.push(create_window_args);
}

for (pane_index, pane) in window.panes.iter().enumerate() {
// TODO disconnect for loop index from window index
for (j, pane) in window.panes.iter().enumerate() {

let pane_index = pane_base_index + j;

// Pane 0 is created by default by the containing window
if pane_index > 0 {
if pane_index > pane_base_index {
let pane_args = build_pane_args(session_name, &window_index);
commands.push(pane_args);
}
Expand Down