Skip to content

Instantly share code, notes, and snippets.

@juliojgarciaperez
Created December 1, 2017 15:17
Show Gist options
  • Save juliojgarciaperez/fc872ff8c8b87f9d838fbd2a73d8964a to your computer and use it in GitHub Desktop.
Save juliojgarciaperez/fc872ff8c8b87f9d838fbd2a73d8964a to your computer and use it in GitHub Desktop.
Shuttle to bash alias
require 'json'
if ARGV.length != 1
puts 'usage: ruby shuttle_alias.rb path_to_shuttle_config.json'
exit
end
config = JSON.parse File.read(ARGV[0])
puts '# Alias from Shuttle'
def perform(node, path = [])
if node.is_a?(Hash)
if node['name']
path << node['name']
alias_name = path.map(&:downcase).join('_')
puts "alias ssh_#{alias_name}='#{node['cmd']}'"
else
node.each do |key, value|
perform(value, path.dup + [key])
end
end
else
node.each do |value|
perform(value, path.dup)
end
end
end
perform config['hosts']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment