Last active
March 26, 2019 07:29
-
-
Save wonderer80/984fc7de3543f1cdf2d64772a2cb707d to your computer and use it in GitHub Desktop.
iterm에서 IP 리스트들에 ssh 접속하기
This file contains 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
ip_list = ARGF.read.gsub('"', '').split("\n") | |
# 최대 10개 까지만 가능 | |
number_string = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'] | |
row_number = (ip_list.size / 2.to_f).ceil | |
add_x = row_number - 2 | |
add_x = 0 if add_x < 0 | |
add_y = row_number | |
add_x_script = [] | |
add_x.times do |i| | |
add_x_script << "set t#{i+2} to (split vertically with default profile)" | |
end | |
add_x_script = add_x_script.join("\n") | |
add_y_script = [] | |
if add_y > 1 | |
add_y.times do |i| | |
if i.zero? | |
add_y_script << "split horizontally with default profile \n" | |
next | |
end | |
add_y_script << <<~Y_SCRIPT | |
tell t#{i} | |
split horizontally with default profile | |
end tell | |
Y_SCRIPT | |
end | |
end | |
add_y_script = add_y_script.join("\n") | |
connect_script = [] | |
ip_list.each_with_index do |ip, index| | |
connect_script << <<~CONNECT_SCRIPT | |
tell #{number_string[index]} session of w1 | |
write text "dncssh #{ip}" | |
end tell | |
CONNECT_SCRIPT | |
end | |
connect_script = connect_script.join("\n") | |
script = <<~SCRIPT | |
osascript <<-eof | |
tell application "iTerm2" | |
tell current window | |
set w1 to (create tab with default profile) | |
tell first session of w1 | |
set t1 to (split vertically with default profile) | |
#{add_x_script} | |
#{add_y_script} | |
end tell | |
#{connect_script} | |
end tell | |
end tell | |
eof | |
SCRIPT | |
puts script | |
system(script) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment