]> git.phdru.name Git - dotfiles.git/blobdiff - .shellrc
Feat(recode-filenames-recursive): Allow to omit parameters
[dotfiles.git] / .shellrc
index e3a0ac7a01c1931230de2926692c7c45ced715fe..9f9242ae5e6a4d3d05448af6f06ceb2be68a222d 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -47,6 +47,48 @@ fi
 # clear screen and history, logout
 chlo() { clear; cd; >$HISTFILE; unset HISTFILE; history -c; logout || exit; }
 
+if [ -n "$STY" -a "$WINDOW" != 0 ]; then
+    #unset MAILCHECK everywhere except for the 1st GNU screen window
+    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"
+    }
+
+    # See https://stackoverflow.com/a/77266926/7976758
+
+    cd_worktree() {
+        if [ $# -ne 1 ]; then
+            echo "Usage: cd_worktree <branch>" >&2
+            return 1
+        fi
+        path="$(git worktree list | grep -F "$1" | awk '{print $1}')"
+        if [ -n "$path" ]; then
+            cd "$path"
+        else
+            echo "Cannot find path for branch '$1'" >&2
+            return 1
+        fi
+    }
+fi
 
 include() {
     cfg="$1"
@@ -121,7 +163,7 @@ mc() {
         rc=1
     fi
 
-    unset MC_FOUND MC_PWD_FILE MC_SLOW MC_TMP_DIR MC_XTERM
+    unset wrapper MC_FOUND MC_PWD_FILE MC_SLOW MC_TMP_DIR MC_XTERM
 
     return $rc
 }