diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 068a773..824cb55 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -379,18 +379,21 @@ nvim-man() { # Creates a git worktree checking it out the first argument in a temporary # directory that is deleted again, if the spawned subshell exits. git-checkout-worktree() { - local GIT_ROOT TEMP_DIR + local GIT_ROOT TEMP_DIR REPO_DIR GIT_ROOT="$(basename "$(git rev-parse --show-toplevel)")" || return - TEMP_DIR="$(mktemp -dp "${TMPDIR:-/tmp}" "$GIT_ROOT.XXXXX")" + TEMP_DIR="$(mktemp -d)" + REPO_DIR="$TEMP_DIR/$GIT_ROOT" - git worktree add "$TEMP_DIR" "$1" - pushd -q "$TEMP_DIR" + git worktree add "$REPO_DIR" "$1" + pushd -q "$REPO_DIR" # Start subshell "$SHELL" # Cleanup when exiting popd -q - git worktree remove "$TEMP_DIR" + git worktree remove "$REPO_DIR" git worktree prune + + command rm -rf "$TEMP_DIR" }