Skip to content

Commit

Permalink
Merge pull request #14 from caarlos0/compat
Browse files Browse the repository at this point in the history
Keep compatibility
  • Loading branch information
caarlos0 authored Aug 20, 2016
2 parents 07802d7 + d27bcf7 commit de11f13
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ gpr() {
}
```

So I can `git push` and `open_pr` in a single, three letters command:
So I can `git push` and `git open-pr` in a single, three letters command:

```console
$ gpr
Expand Down
2 changes: 1 addition & 1 deletion build
Submodule build updated from 8413a0 to 28b8ee
45 changes: 4 additions & 41 deletions git-open-pr
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
#!/bin/sh
_get_repo() {
echo "$1" | sed -e "s/.git$//" -e "s/.*github.com[:/]\(.*\)/\1/"
}

_build_url() {
# shellcheck disable=SC2039
local upstream origin branch repo pr_url target
upstream="$(git config --get remote.upstream.url)"
origin="$(git config --get remote.origin.url)"
branch="$(git symbolic-ref --short HEAD)"
repo="$(_get_repo "$origin")"
pr_url="https://github.com/$repo/pull/new"
target="$1"
test -z "$target" && target="master"
if [ -z "$upstream" ]; then
echo "$pr_url/$target...$branch"
else
# shellcheck disable=SC2039
local origin_name upstream_name
origin_name="$(echo "$repo" | cut -f1 -d'/')"
upstream_name="$(_get_repo "$upstream" | cut -f1 -d'/')"
echo "$pr_url/$upstream_name:$target...$origin_name:$branch"
fi
}

# shellcheck disable=SC2039
__open_pr() {
# shellcheck disable=SC2039
local url
url="$(_build_url "$*")"
if [ "$(uname -s)" = "Darwin" ]; then
open "$url" 2> /dev/null
else
xdg-open "$url" > /dev/null 2> /dev/null
fi
}

# shellcheck disable=SC2128
test "$0" != "$BASH_SOURCE" || echo "$ZSH_EVAL_CONTEXT" | egrep ":file$" ||
__open_pr "$@"
#!/bin/bash
# shellcheck disable=SC1090
source "$(dirname "$0")/git-open-pr.sh"
open-pr "$@"
1 change: 1 addition & 0 deletions git-open-pr.plugin.zsh
37 changes: 37 additions & 0 deletions git-open-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
_get_repo() {
echo "$1" | sed -e "s/.git$//" -e "s/.*github.com[:/]\(.*\)/\1/"
}

_build_url() {
# shellcheck disable=SC2039
local upstream origin branch repo pr_url target
upstream="$(git config --get remote.upstream.url)"
origin="$(git config --get remote.origin.url)"
branch="$(git symbolic-ref --short HEAD)"
repo="$(_get_repo "$origin")"
pr_url="https://github.com/$repo/pull/new"
target="$1"
test -z "$target" && target="master"
if [ -z "$upstream" ]; then
echo "$pr_url/$target...$branch"
else
# shellcheck disable=SC2039
local origin_name upstream_name
origin_name="$(echo "$repo" | cut -f1 -d'/')"
upstream_name="$(_get_repo "$upstream" | cut -f1 -d'/')"
echo "$pr_url/$upstream_name:$target...$origin_name:$branch"
fi
}

# shellcheck disable=SC2039
open-pr() {
# shellcheck disable=SC2039
local url
url="$(_build_url "$*")"
if [ "$(uname -s)" = "Darwin" ]; then
open "$url" 2> /dev/null
else
xdg-open "$url" > /dev/null 2> /dev/null
fi
}
2 changes: 1 addition & 1 deletion tests/test-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# shellcheck disable=1091
source assert.sh
# shellcheck disable=1091
source git-open-pr
source git-open-pr.sh

0 comments on commit de11f13

Please sign in to comment.