]> git.phdru.name Git - git-scripts.git/commitdiff
Feat(git-open): Get remote from the current branch
authorOleg Broytman <phd@phdru.name>
Sun, 20 Aug 2017 21:01:32 +0000 (00:01 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Aug 2017 05:40:13 +0000 (08:40 +0300)
git-open

index 435ef9a186fe4c670cd84f5d72344d22ff360981..bb5d648f4f66488c4cb3fcb1dc4679baa37c48fd 100755 (executable)
--- 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`"