X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=.shellrc;h=5d46454aebef3e37633c23599d11aeb52fdf588d;hb=e7e38d09468bc1f412dade47dff41e3facb26580;hp=b06ba8b24312a12021ba31d788e50cf0e5fcfbb3;hpb=a090b02a21df5d04f3359a79d14eff3b4d72d934;p=dotfiles.git diff --git a/.shellrc b/.shellrc index b06ba8b..5d46454 100644 --- a/.shellrc +++ b/.shellrc @@ -72,6 +72,22 @@ if test -x /usr/bin/git >/dev/null 2>&1; then fi cd "$path_url" } + + # See https://stackoverflow.com/a/77266926/7976758 + + cd_worktree() { + if [ $# -ne 1 ]; then + echo "Usage: cd_worktree " >&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() {