Skip to content

Commit fcbbf91

Browse files
authored
Merge pull request #154 from dineshba/master
Add suffix flag
2 parents 08fa2ab + 8b909f8 commit fcbbf91

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ $ git open --issue
3232

3333
$ git open --print
3434
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH
35+
36+
$ git open --suffix pulls
37+
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
3538
```
3639

3740
## Installation

git-open

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ git open [remote] [branch]
1818
Available options are
1919
c,commit! open current commit
2020
i,issue! open issues page
21+
s,suffix= append this suffix
2122
p,print! just print the url
2223
"
2324

@@ -30,17 +31,23 @@ is_commit=0
3031
is_issue=0
3132
protocol="https"
3233
print_only=0
34+
suffix_flag=""
3335

3436
while test $# != 0; do
3537
case "$1" in
3638
--commit) is_commit=1;;
3739
--issue) is_issue=1;;
40+
--suffix=*) suffix_flag="$1";;
3841
--print) print_only=1;;
3942
--) shift; break ;;
4043
esac
4144
shift
4245
done
4346

47+
# parse suffix from suffix=value
48+
IFS='=' read -ra suffix_flag <<< "$suffix_flag"
49+
suffix=${suffix_flag[1]}
50+
4451
# are we in a git repo?
4552
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
4653
echo "Not a git repository." 1>&2
@@ -238,6 +245,10 @@ elif [[ $remote_ref != "master" ]]; then
238245
openurl="$openurl$providerBranchRef"
239246
fi
240247

248+
if [ "$suffix" ]; then
249+
openurl="$openurl/$suffix"
250+
fi
251+
241252
# get current open browser command
242253
case $( uname -s ) in
243254
Darwin) open='open';;

git-open.1.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## SYNOPSIS
55

6-
`git open` [--issue] [--commit] [remote-name] [branch-name]
6+
`git open` [--issue] [--commit] [--suffix some_suffix] [remote-name] [branch-name]
77

88

99
## DESCRIPTION
@@ -23,6 +23,9 @@ git hosting services are supported.
2323
it will open the webpage with that issue. See `EXAMPLES` for more information.
2424
This only works on GitHub, GitLab, Visual Studio Team Services and Team Foundation Server at the moment.
2525

26+
`-s`, `--suffix` some_suffix
27+
Append the given suffix to the url
28+
2629
`-p`, `--print`
2730
Just print the URL. Do not open it in browser.
2831

@@ -56,6 +59,12 @@ git open --issue
5659
If branches use naming convention of `issues/#123`, it opens
5760
https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123
5861

62+
```sh
63+
git open --suffix pulls
64+
```
65+
66+
It opens the URL https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls
67+
5968
```sh
6069
git open --print
6170
```

test/git-open.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ setup() {
167167
assert_output "https://github.com/paulirish/git-open/commit/${sha}"
168168
}
169169

170+
@test "gh: git open --suffix anySuffix" {
171+
run ../git-open "--suffix" "anySuffix"
172+
assert_output "https://github.com/paulirish/git-open/anySuffix"
173+
}
174+
170175
@test "gh: gist" {
171176
git remote set-url origin "[email protected]:2d84a6db1b41b4020685.git"
172177
run ../git-open

0 commit comments

Comments
 (0)