]> git.phdru.name Git - dotfiles.git/blobdiff - .shellrc
.shellrc: Report error if no directory found for the argument
[dotfiles.git] / .shellrc
index 9a484c15d96f836e0362a4004b71128e7e81dfda..2162d3b5164c77f7f430b824437a5dd3a31774b9 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -225,18 +225,19 @@ if test -x /usr/bin/git >/dev/null 2>&1; then
          cdgitpath remote.$remote.url
       else
 
-         local GIT_REMOTES remote
-         GIT_REMOTES=""
-         for remote in `git remote`; do
-            if git config --get remote.$remote.url | grep -q '^\(/\|\.\./\)'; then
-               GIT_REMOTES="$GIT_REMOTES $remote"
-            fi
-         done
-         GIT_REMOTES=($GIT_REMOTES)
+         if [ -n "$1" ]; then
+            echo "Cannot find directory for remote $1" >&2
+            echo "Usage: cdremote [remote_name]" >&2
+            return 1
+         fi
+
+         _list_remotes '^\(/\|\.\./\)' # (/ or ../ at the beginning)
          if [ ${#GIT_REMOTES[*]} -eq 1 ]; then
             remote=${GIT_REMOTES[0]}
+            unset GIT_REMOTES
             cdgitpath remote.$remote.url
          else
+            unset GIT_REMOTES
             echo "Cannot find directory for any remote" >&2
             echo "Usage: cdremote [remote_name]" >&2
             return 1
@@ -281,11 +282,11 @@ if test -x /usr/bin/git >/dev/null 2>&1; then
             echo "Usage: _list_remotes remote_regexp" >&2
             return 1
          fi
-         GIT_REMOTES=""
+         declare -ag GIT_REMOTES=()
          local remote
          for remote in `git remote`; do
             if git config --get remote.$remote.url | grep -q "$1"; then
-               GIT_REMOTES="$GIT_REMOTES $remote"
+               GIT_REMOTES+=($remote)
             fi
          done
       }