Skip to content

Instantly share code, notes, and snippets.

@noflcl
Created November 3, 2024 14:47
Show Gist options
  • Save noflcl/119cccac5d51bd799e2d903e7daf8329 to your computer and use it in GitHub Desktop.
Save noflcl/119cccac5d51bd799e2d903e7daf8329 to your computer and use it in GitHub Desktop.
tmux launch new windows under "trunk" session starting at branch0
if ! [ "$(tmux ls | cut -d: -f1)" = "trunk" ]; then
tmux new-session -d -s trunk -n branch0
tmux attach-session -t trunk:branch0
elif [[ -z "${TMUX}" ]]; then
branch_id="$(tmux ls | cut -d ' ' -f2)"
tmux new-window -d -n branch$branch_id -t trunk:
tmux attach-session -t trunk:$branch_id
else
branch_id="$(tmux ls | cut -d ' ' -f2)"
tmux new-window -n branch$branch_id -t trunk:
fi
@noflcl
Copy link
Author

noflcl commented Nov 3, 2024

bash script its 95% correct. You call the script and it spawns a new window under the "trunk" session and increments the brach"id" (branch0, branch1, branch2) but keeps you in the window that you are working in (this is key). If you are not in the same terminal (not in a tmux sessions) and you launch the script it creates the new branch and attaches you to that one.
The issue is, the terminal that was active on the previous window doing work (maybe doing work in the quake drop down terminal - completely separate terminal application) is now also switched to the new branch and they are mirrored since they are connected to the same session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment