Created
October 15, 2014 02:12
-
-
Save rlister/e53dc90494f7b4657289 to your computer and use it in GitHub Desktop.
open ssh to list of hosts in iterm tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
## use applescript to start multiple iTerm tabs with ssh into listed hosts | |
## | |
## usage: | |
## | |
## iterm.pl host1 host2 | |
## echo "host1 host2" | iterm.pl | |
## cat file_with_list_of_hosts | iterm.pl | |
use strict; | |
use warnings; | |
## input can come from either args or stdin | |
my @args = @ARGV ? @ARGV : do { my @stdin = <STDIN>; split(/\s+/, "@stdin"); }; | |
## applescript 'words' doesn't parse things with periods correctly, so put one host | |
## per line and parse with 'paragraphs' instead | |
my @hosts = join("\n", @args); | |
## appscript code | |
my $osa =<< "EOF"; | |
set hostlist to "HOSTLIST" | |
tell application "iTerm" | |
activate | |
set Servers to paragraphs of ("@hosts") | |
repeat with nextLine in Servers | |
if length of nextLine is greater than 0 then | |
set server to "nextLine" | |
set term to (current terminal) | |
tell term | |
launch session "Default Session" | |
tell the last session | |
write text "ssh " & nextLine | |
do shell script "/bin/sleep 0.01" | |
end tell | |
end tell | |
end if | |
end repeat | |
terminate the first session of the current terminal | |
end tell | |
EOF | |
## run the script | |
qx[osascript -e '$osa']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment