Created
October 30, 2019 22:30
-
-
Save ta1kt0me/4939aaeedbcefe5c04c5f4eb12441fff to your computer and use it in GitHub Desktop.
converts ssh_config to essh config.lua
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
ssh_config = File.read(ENV.fetch('HOME') + "/.ssh/config") | |
group = {} | |
host = [] | |
ssh_config.each_line do |line| | |
line.strip! | |
if line.start_with?(/Host |host /) | |
unless host.empty? | |
values = host[1..-1].map { |str| [str.strip.split(" ", 2)].to_h }.inject(&:merge) | |
group[host[0]] = values | |
end | |
host = [line.split(" ", 2).last] | |
elsif line.match?(/\A\z/) | |
next | |
else | |
host << line | |
end | |
end | |
config = group.map do |host_name, options| | |
option_contents = options.transform_keys(&:capitalize).map do |key, value| | |
<<~TEMPLATE | |
#{key} = "#{value}", | |
TEMPLATE | |
end | |
option_contents << [ | |
"description = \"\",\n", | |
"tags = {}\n" | |
] | |
<<~TEMPLATE | |
host "#{host_name}" { | |
#{option_contents.join(' ')}} | |
TEMPLATE | |
end | |
puts config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment