diff --git a/.config/zsh/autoload/git/git-checkout-worktree b/.config/zsh/autoload/git/git-checkout-worktree index 3c11651..fc1c1cb 100755 --- a/.config/zsh/autoload/git/git-checkout-worktree +++ b/.config/zsh/autoload/git/git-checkout-worktree @@ -11,13 +11,13 @@ # TODO: If any conflicts arise, all further shells should be interactive instead # of looping forever. -local REPO_NAME REPO_DIR +local REPO_NAME WORKTREE_PATH REPO_NAME="${$(git rev-parse --show-toplevel):t}" || return -REPO_DIR="$(mktemp -d -p "" "worktree.XXX.$REPO_NAME.$1")" +WORKTREE_PATH="$(mktemp -d -p "" "worktree.XXX.$REPO_NAME.$1")" -git worktree add "$REPO_DIR" "$1" -[[ -e "$REPO_DIR" ]] || return 1 -pushd -q "$REPO_DIR" +git worktree add "$WORKTREE_PATH" "$1" +[[ -e "$WORKTREE_PATH" ]] || return 1 +pushd -q "$WORKTREE_PATH" # Start subshell "$SHELL" @@ -28,8 +28,8 @@ popd -q # Restart the subshell until every issue is resolved and the worktree is # removed -until [[ ! -e "$REPO_DIR" ]] || git worktree remove "$REPO_DIR"; do - pushd -q "$REPO_DIR" +until [[ ! -e "$WORKTREE_PATH" ]] || git worktree remove "$WORKTREE_PATH"; do + pushd -q "$WORKTREE_PATH" "$SHELL" errc=$? popd -q