X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=.shellrc;h=2162d3b5164c77f7f430b824437a5dd3a31774b9;hb=bb774a1a3b907df994f1e473e6a5e0dd3daf4c86;hp=d9a20856b7dd7d342a2f1e8110c7c169cdc8cb6a;hpb=1b4145b1d1debe2e0c92e4db7af5f1437fa9d0c5;p=dotfiles.git diff --git a/.shellrc b/.shellrc index d9a2085..2162d3b 100644 --- a/.shellrc +++ b/.shellrc @@ -221,7 +221,28 @@ if test -x /usr/bin/git >/dev/null 2>&1; then return 1 fi - cdgitpath remote.$remote.url + if git config --get remote.$remote.url | grep -q '^\(/\|\.\./\)'; then + cdgitpath remote.$remote.url + else + + 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 + fi + fi } if test -n "$BASH_VERSION"; then @@ -261,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 }