- Notifications
You must be signed in to change notification settings - Fork5
Tool to automatically open multiple ssh connections in iTerm2 by querying ~/.ssh/config.
License
luciopaiva/itermoxyl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
iTermoxyl is command line tool to automatically open multiple ssh connections iniTerm2 by directly querying~/.ssh/config
using patterns provided via the command line.
It is a slightly different medicine for a slightly different problem. iTermoxyl was inspired byitermocil, which was inspired byteamocil.
iTermoxyl is designed to be simple to use, with minimal interaction needed to get it running. Once ssh connections are established, use iTerm2's broadcast input feature to send commands to all machines at once (Shell -> Broadcast input
or simplycmd + shift + i
).
Features:
- magically learns about existing hosts by reading from
~/.ssh/config
- doesn't require any configuration files (tools like
itermocil
andi2cssh
require you to manually create YAML descriptions of your environments) - smart pattern matching: no need to type in the name of each machine you want to connect to
- supportsssh config Include directives
- supports loose matches (see below)
cd
to the destination directory and:
curl -O https://raw.githubusercontent.com/luciopaiva/itermoxyl/master/itermoxylchmod u+x itermoxyl
Make sure to add it to the path so it can be called anywhere.
You need to have iTerm2 installed (obviously), but nothing else. The script is written in Python 2.7 and your macOS already comes with it.
Consider the following sample~/.ssh/config
file:
Host foo-1 HostName 10.0.0.1Host foo-2 HostName 10.0.0.2Host foo-3 HostName 10.0.0.3Host foo-4 HostName 10.0.0.4Host foo-5 HostName 10.0.0.5Host bar-1 HostName 10.0.1.1Host bar-2 HostName 10.0.1.2Host server-1-a HostName 192.168.0.1Host server-1-b HostName 192.168.0.2Host server-2-a HostName 192.168.1.1Host server-2-b HostName 192.168.1.2
Let's try a few combinations. To open:
all
foo
machines:itermoxyl foo
foo-2
andbar-2
:itermoxyl foo,bar 2
server-1-a
andserver-2-a
:itermoxyl server a
foo-1
,foo-2
,foo-3
:itermoxyl foo 1-3
foo-1
,foo-3
,foo-4
,foo-5
:itermoxyl foo 1,3-5
The general rule is:
itermoxyl TERM_0 TERM_1 ... TERM_N
Terms will be joined into the following regular expression:
(?:TERM_0).*?(?:TERM_1).*?(?:TERM_N)
Which acts as a kind of a loose search. Moreover, each term is treated as a potential comma-separated list of names:
TERM => NAME_0,NAME_1,...,NAME_N
Which will get converted to the following regular expression:
(?:NAME_0|NAME_1|NAME_N)
This allows for matches like thefoo,bar
in the example above.
Finally, the last term in a list with more than one term is treated differently. If its name parts are actually numbers, they will exceptionally be translated into the following regular expression:
(?<!\d)(?:NUMBER_0|NUMBER_1|NUMBER_N)$
This was implemented to match specific machine numbers. We usually have a series of machines sharing a same prefix and only differing by the number at the end. Even if the common prefix has numbers in them, we almost never want to match those numbers, only the ones at the very end. That's why this special regular expression has the$
at the end. Moreover, if we specify number2
, we usually want to match only2
and not12
; that's why the expression has a negative lookbehind making sure that no\d
precedes our intended number.
Well, there's one last bit. EachNUMBER
in the pattern above can actually be a range; for instance,1-5
. iTermoxyl will try and match ranges, expanding them accordingly. So if the last term passed in the command line is1,3-5,8-10,12
, the resulting expanded version will be1,3,4,5,8,9,10,12
.
The script will always show all hosts matching your query and ask for confirmation before actually connecting to them.
About
Tool to automatically open multiple ssh connections in iTerm2 by querying ~/.ssh/config.