Skip to content

Instantly share code, notes, and snippets.

@jaylevitt
Created December 30, 2011 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaylevitt/1540691 to your computer and use it in GitHub Desktop.
Save jaylevitt/1540691 to your computer and use it in GitHub Desktop.
Parsing arbitrary options to wrap ssh
#!/usr/bin/env ruby
# gwssh: ssh via a gateway host
# We want to find the hostname so we can add tiptap.com. The hostname will be the
# first string in ARGV that isn't a standalone option and that isn't itself the argument
# for an option (e.g. in "-F configfile", configfile is not the hostname).
# This feels very hacky, and I wonder if there's a more elegant way.
OPTIONS_WITH_ARGUMENTS = 'bcDeFiLlmOopRSw'
skip_argument = false
original_host = nil
ARGV.each do |a|
if skip_argument
skip_argument = false
next
elsif a.start_with?('-')
if OPTIONS_WITH_ARGUMENTS.include?(a[1])
skip_argument = true
next
end
else
original_host = a
end
end
puts original_host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment