From: Oleg Broytman Date: Sun, 20 Aug 2017 21:01:32 +0000 (+0300) Subject: Feat(git-open): Get remote from the current branch X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=cd03f0381699b0e121cc13c477c5d083ec8b21ee;p=git-scripts.git Feat(git-open): Get remote from the current branch --- diff --git a/git-open b/git-open index 435ef9a..bb5d648 100755 --- a/git-open +++ b/git-open @@ -1,8 +1,25 @@ #! /bin/sh +if [ -z "$1" ]; then + branch="`git rev-parse --abbrev-ref HEAD`" + remote="`git config --get branch.$branch.remote`" +elif [ -n "$2" ]; then + echo "Usage: git open [remote_name]" >&2 + exit 1 +else + remote="$1" +fi + +if [ -z "$remote" ]; then + echo "Cannot find remote for branch $branch" >&2 + echo "Usage: git open [remote_name]" >&2 + exit 1 +fi + browser_section="`git config --get web.browser`" browser_cmd="`git config --get browser.\"$browser_section\".cmd`" if [ -z "$browser_cmd" ]; then browser_cmd="webbrowser -n" fi -exec $browser_cmd "`git config --get remote.$1.url`" + +exec $browser_cmd "`git config --get remote.$remote.url`"