diff --git a/README.md b/README.md index 19db3a4..01202d2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ $ git open someremote somebranch $ git open --issue # If branches use naming convention of issues/#123, # opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123 + +$ git open --print +# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH ``` ## Installation @@ -130,12 +133,6 @@ from which this plugin was forked. Please provide examples of the URLs you are parsing with each PR. -You can run `git-open` in `echo` mode, which doesn't open your browser, but just prints the URL to stdout: - -```sh -env BROWSER='echo' ./git-open -``` - ### Testing: You'll need to install [bats](https://github.com/sstephenson/bats#installing-bats-from-source), the Bash automated testing system. It's also available as `brew install bats` diff --git a/git-open b/git-open index 24522dd..86c4dd3 100755 --- a/git-open +++ b/git-open @@ -17,6 +17,7 @@ git open [remote] [branch] Available options are i,issue! open issues page +p,print! just print the url " # https://github.com/koalaman/shellcheck/wiki/SC1090 @@ -26,10 +27,12 @@ SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup" # Defaults is_issue=0 protocol="https" +print_only=0 while test $# != 0; do case "$1" in --issue) is_issue=1;; + --print) print_only=1;; --) shift; break ;; esac shift @@ -243,6 +246,10 @@ case $( uname -s ) in fi;; esac +if (( print_only )); then + BROWSER="echo" +fi + # Allow printing the url if BROWSER=echo if [[ $BROWSER != "echo" ]]; then exec &>/dev/null diff --git a/git-open.1.md b/git-open.1.md index 72bb410..b0a32ca 100644 --- a/git-open.1.md +++ b/git-open.1.md @@ -19,10 +19,12 @@ git hosting services are supported. it will open the webpage with that issue. See `EXAMPLES` for more information. This only works on GitHub, GitLab, Visual Studio Team Services and Team Foundation Server at the moment. +`-p`, `--print` + Just print the URL. Do not open it in browser. + `-h` Show a short help text. - ## EXAMPLES ```sh @@ -50,6 +52,11 @@ git open --issue If branches use naming convention of `issues/#123`, it opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123 +```sh +git open --print +``` + +It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/ ## SUPPORTED GIT HOSTING SERVICES diff --git a/test/git-open.bats b/test/git-open.bats index 541ce9a..7d03216 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -35,6 +35,17 @@ setup() { assert_output --partial "usage: git open" } +## +## Print +## + +@test "print url" { + git remote set-url origin "git@github.com:user/repo.git" + git checkout -B "master" + BROWSER="assert_failure" run ../git-open -p + assert_output "https://github.com/user/repo" +} + ## ## url handling ##