home/git/switch-interactive: fix for branchnames with '/'

This commit is contained in:
Oystein Kristoffer Tveit 2024-07-09 11:05:25 +02:00
parent df71382a47
commit 881aaedd4a
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 7 additions and 2 deletions

View File

@ -7,5 +7,10 @@ fi
BRANCHES=$(cat <(git branch) <(git branch --remotes) | grep --invert-match '^\*\|HEAD ->' | sed 's|^\s*||')
CHOSEN_BRANCH=$(fzf --reverse --info=inline --preview 'git show --color {}' <<<"$BRANCHES")
CLEAN_BRANCH_NAME=$(sed 's|^\s*.*/||' <<<"$CHOSEN_BRANCH")
git switch "$CLEAN_BRANCH_NAME"
CLEAN_BRANCH_NAME=$(sed 's|^\s*||' <<<"$CHOSEN_BRANCH")
for REMOTE in $(git remote); do
CLEAN_BRANCH_NAME=$(sed "s|^${REMOTE}/||" <<<"$CLEAN_BRANCH_NAME")
done
git switch "${CLEAN_BRANCH_NAME}"