]> git.phdru.name Git - dotfiles.git/blobdiff - .shellrc
.shellrc: Fix the list of remotes
[dotfiles.git] / .shellrc
index af5408c81420d3d997e0b6afdd6fc28a7da74e18..205f870cb6d00d2b1de10f62eeda371cf74c7e74 100644 (file)
--- 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
       }
@@ -274,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
       }
 
@@ -327,10 +348,6 @@ mc() {
 
    case "$TERM" in
       screen*) # screen, screen.rxvt
-         if [ "$TERM" = screen.rxvt ]; then
-            MC_SAVE_TERM="$TERM"
-            TERM=rxvt
-         fi
          MC_XTERM="-x"
       ;;
    esac
@@ -382,9 +399,7 @@ mc() {
    fi
 
    [ -n "$MC_SAVE_OPS1" ] && OPS1="$MC_SAVE_OPS1"
-   [ -n "$MC_SAVE_TERM" ] && TERM="$MC_SAVE_TERM"
-   unset MC_FOUND MC_PWD_FILE MC_SAVE_OPS1 MC_SAVE_TERM \
-         MC_SLOW MC_TMP_DIR MC_XTERM
+   unset MC_FOUND MC_PWD_FILE MC_SAVE_OPS1 MC_SLOW MC_TMP_DIR MC_XTERM
 
    return $rc
 }