add .zshrc git checkout methods

This commit is contained in:
jc 2024-03-05 14:30:50 -05:00
commit 46729abddf
No known key found for this signature in database

View file

@ -83,7 +83,7 @@ fcd() {
# clone repository # clone repository
# setopt EXTENDED_GLOB # setopt EXTENDED_GLOB
gc() { cl() {
local url=$1 local url=$1
local ghq_dir="$HOME/ghq" local ghq_dir="$HOME/ghq"
@ -109,6 +109,29 @@ gc() {
git clone $url $project_dir git clone $url $project_dir
} }
# fuzzy find branches and switch to selected branch
gc() {
local selected_branch=$(git branch | fzf | sed 's/^[ \*]*//')
if [ -n "$selected_branch" ]; then
git checkout "$selected_branch"
else
echo "No branch selected"
fi
}
# fuzzy find remote branches and switch to selected branch
gcr() {
git fetch
local selected_branch=$(git branch -r | fzf | sed -E 's/^([ \*]*origin\/[\ *]*)*//')
if [ -n "$selected_branch" ]; then
git checkout "$selected_branch"
else
echo "No branch selected"
fi
}
# get branch if available # get branch if available
parse-git-branch() { parse-git-branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'