]> git.phdru.name Git - dotfiles.git/blobdiff - .shellrc
.bashrc, .shellrc: Move `cdgitpath`
[dotfiles.git] / .shellrc
index 78beaf7ad6991ee6e20a79304de731d21dc89dae..b06ba8b24312a12021ba31d788e50cf0e5fcfbb3 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -52,6 +52,28 @@ if [ -n "$STY" -a "$WINDOW" != 0 ]; then
     unset MAILCHECK
 fi
 
+if test -x /usr/bin/git >/dev/null 2>&1; then
+    # chdir to a directory
+    cdgitpath() {
+        if [ $# -ne 1 ]; then
+            echo "Usage: cdgitpath path_key" >&2
+            return 1
+        fi
+
+        path_key="$1"
+        if [ -z "$path_key" ]; then
+            echo "Usage: cdgitpath path_key" >&2
+            return 1
+        fi
+
+        path_url="`git config --get --path $path_key`"
+        if echo "$path_url" | grep -q '^file:/'; then
+            path_url="`echo \"$path_url\" | sed 's@^file:/\+@/@'`"
+        fi
+        cd "$path_url"
+    }
+fi
+
 include() {
     cfg="$1"
     shift