]> git.phdru.name Git - git-scripts.git/commitdiff
Feat: Split git-open into git-open-remote
authorOleg Broytman <phd@phdru.name>
Wed, 13 Dec 2017 19:35:17 +0000 (22:35 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 13 Dec 2017 19:35:17 +0000 (22:35 +0300)
git-open can now open any config key.
git-open-remote opens remotes URLs.

git-open
git-open-remote [new file with mode: 0755]

index bb5d648f4f66488c4cb3fcb1dc4679baa37c48fd..ebb6e0a5295ecab5930518c518cffd312fb365ee 100755 (executable)
--- a/git-open
+++ b/git-open
@@ -1,18 +1,14 @@
 #! /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
+if [ -z "$1" -o -n "$2" ]; then
+   echo "Usage: git open url_key" >&2
    exit 1
 else
-   remote="$1"
+   url_key="$1"
 fi
 
-if [ -z "$remote" ]; then
-   echo "Cannot find remote for branch $branch" >&2
-   echo "Usage: git open [remote_name]" >&2
+if [ -z "$url_key" ]; then
+   echo "Usage: git open url_key" >&2
    exit 1
 fi
 
@@ -22,4 +18,4 @@ if [ -z "$browser_cmd" ]; then
    browser_cmd="webbrowser -n"
 fi
 
-exec $browser_cmd "`git config --get remote.$remote.url`"
+exec $browser_cmd "`git config --get $url_key`"
diff --git a/git-open-remote b/git-open-remote
new file mode 100755 (executable)
index 0000000..45c3a7e
--- /dev/null
@@ -0,0 +1,19 @@
+#! /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 [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 [remote_name]" >&2
+   exit 1
+fi
+
+exec git-open remote.$remote.url