Skip to content

Commit 8239d0a

Browse files
committed
Add option to print the url
1 parent 7eeee77 commit 8239d0a

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ $ git open someremote somebranch
2929
$ git open --issue
3030
# If branches use naming convention of issues/#123,
3131
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
32+
33+
$ git open --print
34+
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
3235
```
3336

3437
## Installation
@@ -130,12 +133,6 @@ from which this plugin was forked.
130133
131134
Please provide examples of the URLs you are parsing with each PR.
132135
133-
You can run `git-open` in `echo` mode, which doesn't open your browser, but just prints the URL to stdout:
134-
135-
```sh
136-
env BROWSER='echo' ./git-open
137-
```
138-
139136
### Testing:
140137
141138
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`

git-open

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ git open [remote] [branch]
1717
1818
Available options are
1919
i,issue! open issues page
20+
p,print! just print the url
2021
"
2122

2223
# https://github.com/koalaman/shellcheck/wiki/SC1090
@@ -26,10 +27,12 @@ SUBDIRECTORY_OK='Yes' . "$(git --exec-path)/git-sh-setup"
2627
# Defaults
2728
is_issue=0
2829
protocol="https"
30+
print_only=0
2931

3032
while test $# != 0; do
3133
case "$1" in
3234
--issue) is_issue=1;;
35+
--print) print_only=1;;
3336
--) shift; break ;;
3437
esac
3538
shift
@@ -243,6 +246,10 @@ case $( uname -s ) in
243246
fi;;
244247
esac
245248

249+
if (( print_only )); then
250+
BROWSER="echo"
251+
fi
252+
246253
# Allow printing the url if BROWSER=echo
247254
if [[ $BROWSER != "echo" ]]; then
248255
exec &>/dev/null

git-open.1.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ git hosting services are supported.
1919
it will open the webpage with that issue. See `EXAMPLES` for more information.
2020
This only works on GitHub, GitLab, Visual Studio Team Services and Team Foundation Server at the moment.
2121

22+
`-p`, `--print`
23+
Just print the URL. Do not open it in browser.
24+
2225
`-h`
2326
Show a short help text.
2427

25-
2628
## EXAMPLES
2729

2830
```sh
@@ -50,6 +52,11 @@ git open --issue
5052
If branches use naming convention of `issues/#123`, it opens
5153
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
5254

55+
```sh
56+
git open --print
57+
```
58+
59+
It prints the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/
5360

5461
## SUPPORTED GIT HOSTING SERVICES
5562

test/git-open.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ setup() {
3535
assert_output --partial "usage: git open"
3636
}
3737

38+
##
39+
## Print
40+
##
41+
42+
@test "print url" {
43+
git remote set-url origin "[email protected]:user/repo.git"
44+
git checkout -B "master"
45+
BROWSER="assert_failure" run ../git-open -p
46+
assert_output "https://github.com/user/repo"
47+
}
48+
3849
##
3950
## url handling
4051
##

0 commit comments

Comments
 (0)