Created
December 7, 2023 06:43
-
-
Save Fatpandac/d0442e5cc365d21daf28e75204f87fe7 to your computer and use it in GitHub Desktop.
Quick checkout and delete branch by fzf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gitSelectBranch() { | |
selected=$(git branch -a | grep -v "*" | fzf | sed -e "s/remotes\/origin\///" | sed 's/^\s*\|\s*$//g') | |
echo "$selected" | |
} | |
gitSelectBranchOprateFactory() { | |
comd=$1 | |
branch=$2 | |
if [ -z $2 ];then | |
selected=$(gitSelectBranch) | |
echo "$selected" | |
if [ -z != $selected ]; then | |
eval "$1 $selected" | |
fi | |
else | |
eval "$1 $2" | |
fi | |
} | |
unalias gc | |
gc() { | |
comd="git checkout" | |
gitSelectBranchOprateFactory $comd $1 | |
} | |
unalias gbd | |
gbd() { | |
comd="git branch -D" | |
gitSelectBranchOprateFactory $comd $1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment