-
Notifications
You must be signed in to change notification settings - Fork 17
add tmux as a replacement for "restore-terminals" #204
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
Conversation
WalkthroughA new Bash script, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant dev-tmux.sh
participant OS/PackageManager
participant tmux
User->>dev-tmux.sh: Run script with command (e.g., create, attach, install)
alt Install tmux
dev-tmux.sh->>OS/PackageManager: Check/install tmux
OS/PackageManager-->>dev-tmux.sh: tmux installed
end
alt Create config
dev-tmux.sh->>User: Prompt to overwrite .tmux.conf
User-->>dev-tmux.sh: Confirm/deny
dev-tmux.sh->>FileSystem: Write config file
end
alt Create session
dev-tmux.sh->>tmux: Check for existing session
tmux-->>dev-tmux.sh: Session exists/doesn't exist
dev-tmux.sh->>tmux: Kill session (if forced)
dev-tmux.sh->>tmux: Create new session "echo-dev"
dev-tmux.sh->>tmux: Setup windows and panes, run commands
end
alt Attach session
dev-tmux.sh->>tmux: Attach to "echo-dev"
end
alt Show status/help
dev-tmux.sh->>User: Print session info/help
end
LGTM. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Tmux Script Fails to Create Balanced Pane Layout
The echo/dev-tmux.sh script's create_session function incorrectly configures the workers window pane layout. Despite a comment suggesting an "80/20 split" for workers and scheduler, the code attempts to create three panes. The consecutive tmux split-window -h -p 80 and -p 20 commands result in an unintended and unbalanced layout (e.g., ~20%/64%/16%) because the second split subdivides the previously created 80% pane, failing to achieve the stated proportions or a proper three-pane division for the intended services (workers, workers-cpu, scheduler).
echo/dev-tmux.sh#L361-L377
Lines 361 to 377 in ca77dca
| # Window 2: Workers and Scheduler (split 80/20) | |
| tmux new-window -t "$SESSION_NAME" -n "workers" -c "$project_root" | |
| # Split the workers window horizontally (80% workers, 20% scheduler) | |
| tmux split-window -t "$SESSION_NAME:workers" -h -p 80 -c "$project_root" | |
| tmux split-window -t "$SESSION_NAME:workers" -h -p 20 -c "$project_root" | |
| # Rename the panes for clarity | |
| tmux select-pane -t "$SESSION_NAME:workers.0" -T "workers" | |
| tmux select-pane -t "$SESSION_NAME:workers.1" -T "workers-cpu" | |
| tmux select-pane -t "$SESSION_NAME:workers.2" -T "scheduler" | |
| # Send commands to each pane | |
| tmux send-keys -t "$SESSION_NAME:workers.0" "cd server && source .venv/bin/activate && ./run-worker.sh" C-m | |
| tmux send-keys -t "$SESSION_NAME:workers.1" "cd server && source .venv/bin/activate && ./run-worker-cpu.sh" C-m | |
| tmux send-keys -t "$SESSION_NAME:workers.2" "cd server && source .venv/bin/activate && ./run-scheduler.sh" C-m |
Was this report helpful? Give feedback by reacting with 👍 or 👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
echo/dev-tmux.sh(1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
echo/dev-tmux.sh
[warning] 12-12: BLUE appears unused. Verify use (or export if used externally).
(SC2034)
[warning] 354-354: Declare and assign separately to avoid masking return values.
(SC2155)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Cursor BugBot
- GitHub Check: ci-check-server
- GitHub Check: Analyze (javascript-typescript)
| if [[ -f "$config_file" ]]; then | ||
| print_warning "Tmux configuration already exists at $config_file" | ||
| read -p "Do you want to replace it with vim-style config? (y/N): " -n 1 -r | ||
| echo | ||
| if [[ ! $REPLY =~ ^[Yy]$ ]]; then | ||
| print_status "Keeping existing configuration" | ||
| return | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Interactive prompt blocks automation – offer --yes flag
CI scripts or make dev flows choke on the read -p confirmation. Provide a non-interactive override (e.g., --yes).
No diff given—design choice needed.
🤖 Prompt for AI Agents
In echo/dev-tmux.sh around lines 94 to 101, the interactive read prompt blocks
automation in CI or scripted runs. Add a command-line flag like --yes to bypass
the prompt and automatically confirm replacing the config. Modify the script to
check for this flag early and skip the read prompt if it is present, proceeding
as if the user answered yes.
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' # No Color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Kill the unused BLUE constant
BLUE is defined but never referenced (ShellCheck SC2034). Dead code ≠ 100x.
- BLUE='\033[0;34m'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color |
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 12-12: BLUE appears unused. Verify use (or export if used externally).
(SC2034)
🤖 Prompt for AI Agents
In echo/dev-tmux.sh around lines 8 to 13, the BLUE color constant is defined but
never used. Remove the line defining BLUE='\033[0;34m' to eliminate this unused
variable and clean up the script.
| # Echo Development Environment Tmux Setup Script | ||
| # This script sets up a complete tmux development environment with all services | ||
|
|
||
| set -e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add set -u -o pipefail for bullet-proof error handling
Running without set -u (undefined-var detection) and -o pipefail (capture failures in pipelines) leaves gaps in safety nets—unexpected typos or silent pipe errors can torpedo the whole session later. Hardening now avoids future yak-shaving.
set -e
+set -u
+set -o pipefail📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| set -e | |
| set -e | |
| set -u | |
| set -o pipefail |
🤖 Prompt for AI Agents
In echo/dev-tmux.sh at line 6, the script currently uses only 'set -e' for error
handling. To improve robustness, add 'set -u' to detect undefined variables and
'-o pipefail' to ensure pipeline failures are caught. Update the line to include
these options so the script fails fast and safely on errors or undefined
variables.
| print_status "Creating tmux session '$SESSION_NAME'..." | ||
|
|
||
| # Get the absolute path to the project root | ||
| local project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Avoid masking subshell exit status with inline assignment
ShellCheck SC2155 is right—assign and cd separately to keep exit codes intact and readability sane.
- local project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ local script_dir
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ local project_root="$script_dir"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| local project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| local script_dir | |
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| local project_root="$script_dir" |
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 354-354: Declare and assign separately to avoid masking return values.
(SC2155)
🤖 Prompt for AI Agents
In echo/dev-tmux.sh at line 354, the inline assignment with cd masks the
subshell's exit status. To fix this, separate the cd command and the assignment
into two steps: first run cd to change the directory and check its exit status,
then assign the output of pwd to project_root. This preserves the exit status
and improves readability.
| # Status bar content | ||
| set -g status-left-length 40 | ||
| set -g status-left "#[fg=green]#S #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]" | ||
|
|
||
| set -g status-right-length 60 | ||
| set -g status-right "#[fg=colour136]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default] #[fg=colour33]%H:%M#[default]" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
/proc/loadavg breaks on macOS – use cross-platform fallback
The generated status bar spams errors on systems without /proc. Pipe uptime thru awk for portable load info.
-set -g status-right "#[fg=colour136]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default] #[fg=colour33]%H:%M#[default]"
+set -g status-right "#[fg=colour136]#(uptime | awk -F'load averages?: ' '{print $2}' | cut -d',' -f1-3)#[default] #[fg=colour33]%H:%M#[default]"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Status bar content | |
| set -g status-left-length 40 | |
| set -g status-left "#[fg=green]#S #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]" | |
| set -g status-right-length 60 | |
| set -g status-right "#[fg=colour136]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default] #[fg=colour33]%H:%M#[default]" | |
| # Status bar content | |
| set -g status-left-length 40 | |
| set -g status-left "#[fg=green]#S #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]" | |
| set -g status-right-length 60 | |
| set -g status-right "#[fg=colour136]#(uptime | awk -F'load averages?: ' '{print $2}' | cut -d',' -f1-3)#[default] #[fg=colour33]%H:%M#[default]" |
🤖 Prompt for AI Agents
In echo/dev-tmux.sh around lines 308 to 314, the status-right configuration uses
/proc/loadavg which causes errors on macOS as it lacks /proc. Replace the
command that reads /proc/loadavg with a cross-platform alternative by piping the
output of uptime through awk to extract the load averages. Update the
status-right line to use this portable command to avoid errors on non-Linux
systems.
| tmux split-window -t "$SESSION_NAME:workers" -h -p 80 -c "$project_root" | ||
| tmux split-window -t "$SESSION_NAME:workers" -h -p 20 -c "$project_root" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Pane split order is non-deterministic – explicitly target pane indices
A second -h split runs relative to the current pane, which depends on user focus and tmux defaults. Target pane workers.0 to lock layout.
- tmux split-window -t "$SESSION_NAME:workers" -h -p 80 -c "$project_root"
- tmux split-window -t "$SESSION_NAME:workers" -h -p 20 -c "$project_root"
+ tmux split-window -t "$SESSION_NAME:workers.0" -h -p 80 -c "$project_root"
+ tmux split-window -t "$SESSION_NAME:workers.1" -h -p 25 -c "$project_root"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| tmux split-window -t "$SESSION_NAME:workers" -h -p 80 -c "$project_root" | |
| tmux split-window -t "$SESSION_NAME:workers" -h -p 20 -c "$project_root" | |
| tmux split-window -t "$SESSION_NAME:workers.0" -h -p 80 -c "$project_root" | |
| tmux split-window -t "$SESSION_NAME:workers.1" -h -p 25 -c "$project_root" |
🤖 Prompt for AI Agents
In echo/dev-tmux.sh around lines 366 to 368, the tmux split-window commands use
relative splits with the -h flag, which depend on the current pane focus and can
lead to non-deterministic pane layouts. To fix this, explicitly specify the
target pane index (e.g., workers.0) in the -t option for each split-window
command to ensure the splits always occur relative to the same pane, locking the
layout deterministically.
Summary by CodeRabbit