X-Git-Url: https://git.phdru.name/?p=dotfiles.git;a=blobdiff_plain;f=.shellrc;h=205f870cb6d00d2b1de10f62eeda371cf74c7e74;hp=3eeb62129e715602183429a0d902a538828d7a19;hb=4769085847cfb7b3ab762310120cebf41cbee7ce;hpb=2f22015c59cf7d74f8ebfdf025c1ec0503cf867f diff --git a/.shellrc b/.shellrc index 3eeb621..205f870 100644 --- a/.shellrc +++ b/.shellrc @@ -225,17 +225,19 @@ if test -x /usr/bin/git >/dev/null 2>&1; then cdgitpath remote.$remote.url else - local remote - local -a GIT_REMOTES=() - for remote in `git remote`; do - if git config --get remote.$remote.url | grep -q '^\(/\|\.\./\)'; then - GIT_REMOTES+=($remote) - fi - done + 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 @@ -293,7 +295,7 @@ if test -x /usr/bin/git >/dev/null 2>&1; then _list_remotes_completion() { local cur="${COMP_WORDS[COMP_CWORD]}"; _list_remotes "$1" - COMPREPLY=(`compgen -W "$GIT_REMOTES" -- "$cur"`) + COMPREPLY=(`compgen -W "${GIT_REMOTES[*]}" -- "$cur"`) unset GIT_REMOTES }