Created
April 20, 2018 17:44
-
-
Save mkutz/24222c06342d8e69b8091a9cf0ceab21 to your computer and use it in GitHub Desktop.
Simple Groovy script to open an URL under Linux, as well as OSX or Windows.
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 groovy | |
/* | |
* define CLI | |
*/ | |
def cli = new CliBuilder(usage: "${this.class.name} [options]") | |
cli.usage() | |
/* | |
* open URL | |
*/ | |
String command = [ | |
"windows": "start", | |
"linux": "xdg-open", | |
"darwin": "open" | |
].find { key, value -> System.properties["os.name"].toLowerCase().contains(key) }.value | |
Process process = "${command} \"${args.join()}\".execute() | |
process.consumeProcessOutput(System.out, System.err) | |
process.waitFor() | |
System.exit(process.exitValue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment