Updated README.md
This commit is contained in:
68
README.md
68
README.md
@@ -4,12 +4,17 @@ A hack tmux menu script to manage multiple tmux sessions
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
REQ: tmux v3+
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Need
|
||||||
|
|
||||||
After I discovered tmux I searched for a way to manage multiple groups of tmux sessions under one unified script.
|
After I discovered tmux I searched for a way to manage multiple groups of tmux sessions under one unified script.
|
||||||
|
|
||||||
Not finding anything (or maybe just not looking well enough) I decided to write my own.
|
Not finding anything (or maybe just not looking well enough) I decided to write my own.
|
||||||
|
|
||||||
It ain't pretty, but I've been using for over a year now and it's become an integral part of my workflow. Maybe
|
It ain't pretty, but I've been using for a couple of years now and it's become an integral part of my workflow.
|
||||||
someone could benefit from it? Or help me extend it?
|
|
||||||
|
|
||||||
My setup works this way:
|
My setup works this way:
|
||||||
|
|
||||||
@@ -20,43 +25,48 @@ Imagine you have multiple SSH connections
|
|||||||
* database-dev
|
* database-dev
|
||||||
* database-prod
|
* database-prod
|
||||||
|
|
||||||
... and you want to group them together in similar groups.
|
and you want to group them together in similar groups.
|
||||||
|
|
||||||
With this script you can name collections of sessions and switch between them easily with just a few keystrokes.
|
With this script you can name collections of sessions and switch between them easily with just a few keystrokes.
|
||||||
|
|
||||||
Let's see an example using the above connections:
|
Let's see an example using the above connections:
|
||||||
|
|
||||||
case $session in
|
```shell
|
||||||
web)
|
case $session in
|
||||||
if [[ $tcheck == 0 ]]; then
|
web)
|
||||||
tmux new-session -d -s web
|
if [[ $tcheck == 0 ]]; then
|
||||||
tmux rename-window 'local'
|
tmux new-session -d -s web
|
||||||
tmux new-window -t 1 -n 'root@web-dev' 'exec ssh root@web-dev.example.org'
|
tmux rename-window 'local'
|
||||||
tmux new-window -t:2 -n 'user@web-prod' 'exec ssh user@webprod.example.org'
|
tmux new-window -t 1 -n 'root@web-dev' 'exec ssh root@web-dev.example.org'
|
||||||
fi
|
tmux new-window -t:2 -n 'user@web-prod' 'exec ssh user@webprod.example.org'
|
||||||
tmux attach-session -t web
|
fi
|
||||||
;;
|
tmux attach-session -t web
|
||||||
|
;;
|
||||||
|
|
||||||
case $session in
|
case $session in
|
||||||
database)
|
database)
|
||||||
if [[ $tcheck == 0 ]]; then
|
if [[ $tcheck == 0 ]]; then
|
||||||
tmux new-session -d -s database
|
tmux new-session -d -s database
|
||||||
tmux rename-window 'local'
|
tmux rename-window 'local'
|
||||||
tmux new-window -t 1 -n 'root@database-dev' 'exec ssh root@databasedev.example.org'
|
tmux new-window -t 1 -n 'root@database-dev' 'exec ssh root@databasedev.example.org'
|
||||||
tmux new-window -t:2 -n 'user@database-prod' 'exec ssh user@wdatabase.example.org'
|
tmux new-window -t:2 -n 'user@database-prod' 'exec ssh user@wdatabase.example.org'
|
||||||
fi
|
fi
|
||||||
tmux attach-session -t database
|
tmux attach-session -t database
|
||||||
;;
|
;;
|
||||||
|
```
|
||||||
|
|
||||||
|
Calling the script with a pre-determined session name (ex: `./tmux-menu.sh web` or `./tmux-menu.sh database`) first checks to see if there is already a session group with that name. If not, it creates a new group with the commands you specify and names each connection in tmux.
|
||||||
Calling the script with a pre-determined session name (ex: `./tmux-menu.sh web` or `tmux-menu.sh database`) first
|
|
||||||
checks to see if there is already a session group with that name. If not, it creates a new group with the
|
|
||||||
commands you specify and names each connection in tmux.
|
|
||||||
|
|
||||||
If the session group *does* already exist, it simply switches you to that group.
|
If the session group *does* already exist, it simply switches you to that group.
|
||||||
|
|
||||||
If you alias `tmux-menu.sh` to something shorter (like `tm`), switching between active sessions is as
|
If you alias `tmux-menu.sh` to something shorter (like `tm`), switching between active sessions is as easy as `Ctrl-A + d` (to detach) and `tm web` (to attach or create the web group).
|
||||||
easy as `Ctrl-A + d` (to detach) and `tm web` (to attach or create the web group).
|
|
||||||
|
|
||||||
Killing session groups is as easy as `tmux-session kill -t web`.
|
Killing session groups is as easy as `tmux-session kill -t web`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Use
|
||||||
|
|
||||||
|
I've found that I use this script on different servers with different configurations. So I copy the `tmux-menu.template.sh` to `tmux-menu.sh` and then alias that to `tm`. My `.gitignore` prevents the customized `tmux-menu.sh` from being version controlled.
|
||||||
|
|
||||||
|
I also include my `/.tmux.conf` file with comments about what does what. If you choose to use it, make sure to copy it to your home directory.
|
||||||
Reference in New Issue
Block a user