zsh:funcs:git-checkout-worktree: Remove -p flag
As under OSX the -p flag does not exist, it seems safer to just use `mktemp -d` and create the worktree under that directory. This just has the disadvantage of one more dir to display in the `PWD`.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user