tmux_ssh/README.md

60 lines
2.4 KiB
Markdown
Raw Normal View History

2019-05-23 01:37:43 +02:00
ssh.sh is a small wrapper script around ssh to open a ssh connection in tmux.
2016-08-28 20:27:02 +02:00
The main purpose of this script is to configure the tmux windows titles with
the hostnames provided by the ssh command line itself. I have often to connect
to cloud hosts with crude hostnames I can't remember and therefore I prefer to
use cnames or hostnames set via .ssh/config - and exactly these names should
be used for window names in tmux and not set via escape sequences (pane
titles) from within the target hosts to their crude names.
2019-05-23 01:37:43 +02:00
Additionally a map file can be configured which stores styles for tmux panes
matched by patterns - like in ssh_config the first count matches. This makes
it easier to see which pane has a ssh connection to which host when e.g. the
hostnames are the same but from different subdomains.
Simply place ssh.sh, ssh.conf and ssh.map into the same directory. It should
not interfere with existing configs because it starts an own server at an own
socket with an own session. For testing simply run "sh ssh.sh -c targethost".
2016-08-28 20:27:02 +02:00
Without arguments it starts a session without ssh and attaches a xterm to it.
It can be configured via a shell alias like this:
2016-08-29 04:46:15 +02:00
```
2019-05-23 01:37:43 +02:00
alias ssh="sh ~/.tmux/ssh.sh -c"
2016-08-29 04:46:15 +02:00
```
2019-05-23 01:37:43 +02:00
I wrote and tested this with OpenBSD's ksh. I guess bash should work too but
2016-08-28 20:27:02 +02:00
not tested yet.
As a lucky OpenBSD user I also use cwm as my preferred window manager. This
2019-05-23 01:37:43 +02:00
script can also be used with cwm's wonderful "ssh to" dialog by placing the
following into your .cwmrc:
2016-08-29 04:46:15 +02:00
```
2019-05-23 01:37:43 +02:00
command term 'sh -c ". ~/.tmux/ssh.sh -c $1"'
2016-08-28 20:39:33 +02:00
bind CM-Return xterm
2016-08-30 00:02:28 +02:00
# ...to launch the server only with one window with default shell
2019-05-23 01:37:43 +02:00
bind CM-s 'sh -c ". ~/.tmux/ssh.sh -c"'
2016-08-30 00:00:31 +02:00
2016-08-29 04:46:15 +02:00
# ...and if autogroup is preferred
2016-08-28 20:39:33 +02:00
autogroup 1 "SSH,XTerm"
2019-05-23 01:37:43 +02:00
# ...or if you want prefer to use rofi place this into the config
ssh-command: "sh ~/.tmux/ssh.sh -c {host}";
2016-08-29 04:46:15 +02:00
```
2020-08-19 16:59:47 +02:00
Or if you prefer rofi, them place this line into .config/rofi/config.rasi:
```
ssh-command: "/bin/sh .tmux_ssh/ssh.sh -c {host}";
```
2019-05-23 01:37:43 +02:00
If you have xdotool installed it also focusses the xterm which is attached to
2016-08-28 20:27:02 +02:00
the session or spawns a new term and reattaches to an existing session.
Special thanks go to the OpenBSD developers for providing such a high quality
and stable operating system and to Nicholas Marriot for tmux - a tool I can't
work without it and his patience to answer my questions.
Enjoy.
2016-08-29 06:55:13 +02:00
With my sample config it looks then like this:
![Screenshot](screenshot/tmux_ssh.png "Example config looks like this.")