Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To make ghwd able to be incorporated inside other scripts I added a -r, -s, and -v option. -r is return only mode, and only returns the URL that would have been opened and exits; this is for use in scripts that might want to do other operations than opening the URL. The -s option is the silent option, which silences all output, and is the flag most scripts would want to use to best incorporate ghwd. Each occurrence of a -v flag increments the verbosity variable so that there can be varying levels of verbosity in the future, e.g., "ghwd -vvv" could reveal debug information. The variable defaults to 1, and therefore causes ghwd to function exactly as it does now, outputting the URL before opening it.
I also noticed some echo statements that were reporting errors were not redirected to stderr, so fixed that. And changed the () to {} on ln. 93, because the parenthesis create a subshell, which is the shell exited with exit status 1 by the exit command—in other words, when ghwd can't find an appropriate opener and wants to tell the user that it didn't anticipate their operating system, it does so in a subshell and exits from that subshell with exit status 1, then exits from the actual ghwd shell with exit status 0, even though an error occured.
I'll be happy to write a manpage and update the README with usage information pertaining to these new options once I know what you think of them :)
note: this update will allow @stour to test his added functionality from #20, since now ghwd will be able to just return the URLs.
test cases
ghwd -v
>https://github.com/klmanion/ghwd/tree/feature/silent-and-verbose/bin
>opens URL
ghwd
[same as above]
ghwd -s
>opens URL
ghwd -r
>https://github.com/klmanion/ghwd/tree/feature/silent-and-verbose/bin