Created
December 30, 2011 17:26
-
-
Save jaylevitt/1540691 to your computer and use it in GitHub Desktop.
Parsing arbitrary options to wrap 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
#!/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