Skip to content

Commit c648341

Browse files
authored
Merge pull request #20 from yysd5/fix/command-execution-delay
Fix/command execution delay
2 parents 6782315 + 767a5df commit c648341

7 files changed

Lines changed: 48 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "tsps"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
edition = "2024"
55
description = "Quickly set up tmux workspaces by splitting windows into multiple panes"
66
license = "MIT"
7-
repository = "https://github.com/yyossy5/tsps"
7+
repository = "https://github.com/yysd5/tsps"
88
authors = ["yyossy5 <hm.hr.yossy@gmail.com>"]
9-
homepage = "https://github.com/yyossy5/tsps"
9+
homepage = "https://github.com/yysd5/tsps"
1010
readme = "README.md"
1111
keywords = ["tmux", "cli", "terminal", "workspace"]
1212
categories = ["command-line-utilities"]

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
## Building from source
99

1010
```bash
11-
git clone https://github.com/yyossy5/tsps.git
11+
git clone https://github.com/yysd5/tsps.git
1212
cd tsps
1313
cargo build --release
1414
```

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Crates.io](https://img.shields.io/crates/v/tsps)](https://crates.io/crates/tsps)
44
[![Downloads](https://img.shields.io/crates/d/tsps)](https://crates.io/crates/tsps)
5-
[![License](https://img.shields.io/crates/l/tsps)](https://github.com/yyossy5/tsps/blob/main/LICENSE)
5+
[![License](https://img.shields.io/crates/l/tsps)](https://github.com/yysd5/tsps/blob/main/LICENSE)
66

77
Quickly set up your tmux workspace by splitting a window into multiple panes at a specified directory with a single command.
88

@@ -34,7 +34,7 @@ cargo install tsps
3434

3535
```bash
3636
# Download the latest release
37-
curl -L https://github.com/yyossy5/tsps/releases/latest/download/tsps-aarch64-apple-darwin -o tsps
37+
curl -L https://github.com/yysd5/tsps/releases/latest/download/tsps-aarch64-apple-darwin -o tsps
3838

3939
# Make it executable
4040
chmod +x tsps
@@ -74,6 +74,9 @@ tsps --layout examples/dev.yaml --directory /path/to/different/project
7474

7575
# Short form with directory override
7676
tsps -l examples/dev.yaml -d /path/to/project
77+
78+
# Adjust the delay before executing commands (in milliseconds, default: 2000)
79+
tsps -l examples/dev.yaml --delay 3000
7780
```
7881

7982
#### Example Layout File
@@ -138,6 +141,18 @@ tsps -l ~/layouts/dev.yaml -d ~/projects/mobile
138141

139142
This is particularly useful when you have standardized development workflows but work on multiple projects.
140143

144+
#### Command Execution Delay
145+
146+
If your environment causes commands to fail or display incorrectly, you can increase the delay before commands are executed:
147+
148+
```bash
149+
# Wait for 3 seconds instead of the default 2 seconds
150+
tsps -l ~/layouts/dev.yaml --delay 3000
151+
```
152+
153+
The default delay is 2000ms (2 seconds), which should be sufficient for most environments.
154+
Increase this value if you find that commands are being sent before the shell is ready.
155+
141156
#### Size Specification Examples
142157

143158
```yaml
@@ -176,7 +191,7 @@ cargo install-update tsps
176191

177192
```bash
178193
# Download the latest release
179-
curl -L https://github.com/yyossy5/tsps/releases/latest/download/tsps-aarch64-apple-darwin -o tsps
194+
curl -L https://github.com/yysd5/tsps/releases/latest/download/tsps-aarch64-apple-darwin -o tsps
180195

181196
# Make it executable
182197
chmod +x tsps

examples/dev.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ panes:
1111
- "nvim ."
1212
focus: true
1313

14-
# Claude Code (top-right, smaller)
15-
- id: "claude"
14+
# Gemini CLI (top-right, smaller)
15+
- id: "gemini"
1616
split: "vertical"
1717
size: "38%"
1818
commands:
19-
- "claude"
19+
- "gemini"
2020

2121
# General terminal (bottom-left)
2222
- id: "terminal"

src/layout.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl LayoutConfig {
4343
}
4444

4545
/// Apply layout to tmux
46-
pub fn apply_to_tmux(&self) -> Result<(), Box<dyn std::error::Error>> {
46+
pub fn apply_to_tmux(&self, delay: u64) -> Result<(), Box<dyn std::error::Error>> {
4747
// Check if directory exists
4848
let target_dir = Path::new(&self.workspace.directory);
4949
if !target_dir.exists() {
@@ -69,7 +69,7 @@ impl LayoutConfig {
6969
self.adjust_pane_sizes()?;
7070

7171
// Execute commands in each pane
72-
self.execute_commands()?;
72+
self.execute_commands(delay)?;
7373

7474
// Set focus
7575
self.set_focus()?;
@@ -118,8 +118,8 @@ impl LayoutConfig {
118118

119119
/// Adjust pane sizes after layout is applied
120120
fn adjust_pane_sizes(&self) -> Result<(), Box<dyn std::error::Error>> {
121-
// Wait a moment for layout to settle
122-
std::thread::sleep(std::time::Duration::from_millis(100));
121+
// Wait for layout to settle
122+
std::thread::sleep(std::time::Duration::from_millis(500));
123123

124124
// First pass: adjust individual pane sizes
125125
for (index, pane) in self.panes.iter().enumerate() {
@@ -208,13 +208,23 @@ impl LayoutConfig {
208208
}
209209

210210
/// Execute commands in each pane
211-
fn execute_commands(&self) -> Result<(), Box<dyn std::error::Error>> {
211+
fn execute_commands(&self, delay: u64) -> Result<(), Box<dyn std::error::Error>> {
212+
// Wait for all panes to settle after creation and resizing
213+
std::thread::sleep(std::time::Duration::from_millis(delay));
214+
212215
for (index, pane) in self.panes.iter().enumerate() {
216+
if pane.commands.is_empty() {
217+
continue;
218+
}
219+
213220
// Select pane
214221
Command::new("tmux")
215222
.args(["select-pane", "-t", &index.to_string()])
216223
.status()?;
217224

225+
// Delay between pane selection and command execution
226+
std::thread::sleep(std::time::Duration::from_millis(300));
227+
218228
// Execute commands
219229
for command in &pane.commands {
220230
Command::new("tmux")

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ struct Cli {
1919
#[arg(short, long, value_name = "DIRECTORY")]
2020
directory: Option<PathBuf>,
2121

22+
/// Delay before executing commands in milliseconds
23+
#[arg(short = 'D', long, value_name = "MS", default_value = "2000")]
24+
delay: u64,
25+
2226
/// Remaining arguments for traditional usage (pane_count and directory)
2327
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
2428
args: Vec<String>,
@@ -35,7 +39,7 @@ fn main() {
3539

3640
// If layout file is specified
3741
if let Some(layout_file) = cli.layout {
38-
match apply_layout_file(&layout_file, cli.directory.as_ref()) {
42+
match apply_layout_file(&layout_file, cli.directory.as_ref(), cli.delay) {
3943
Ok(()) => return,
4044
Err(e) => {
4145
eprintln!("Error: Failed to apply layout: {}", e);
@@ -125,6 +129,7 @@ fn main() {
125129
fn apply_layout_file(
126130
layout_file: &PathBuf,
127131
override_directory: Option<&PathBuf>,
132+
delay: u64,
128133
) -> Result<(), Box<dyn std::error::Error>> {
129134
let mut layout = LayoutConfig::from_file(layout_file)?;
130135

@@ -133,6 +138,6 @@ fn apply_layout_file(
133138
layout.workspace.directory = dir.to_string_lossy().to_string();
134139
}
135140

136-
layout.apply_to_tmux()?;
141+
layout.apply_to_tmux(delay)?;
137142
Ok(())
138143
}

0 commit comments

Comments
 (0)