From cc609a708e237e4daddbe294a9e41d8052ee8a5c Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:35:47 -0500 Subject: [PATCH] (zsh) update gc/gcr functions --- zsh/.zshrc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zsh/.zshrc b/zsh/.zshrc index 5ad5113..90acfb1 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -129,6 +129,12 @@ cl() { # fuzzy find branches and switch to selected branch gc() { + if [ $# -eq 1 ]; then + local selected_branch=$(git branch | fzf --filter="$1" --select-1 --exit-0 | head -1 | sed 's/^[ \*]*//') + git checkout "$selected_branch" + return + fi + local selected_branch=$(git branch | fzf | sed 's/^[ \*]*//') if [ -n "$selected_branch" ]; then @@ -141,6 +147,13 @@ gc() { # fuzzy find remote branches and switch to selected branch gcr() { git fetch + + if [ $# -eq 1 ]; then + local selected_branch=$(git branch -r | fzf --filter="$1" --select-1 --exit-0 | head -1 | sed -E 's/^([ \*]*origin\/[\ *]*)*//') + git checkout "$selected_branch" + return + fi + local selected_branch=$(git branch -r | fzf | sed -E 's/^([ \*]*origin\/[\ *]*)*//') if [ -n "$selected_branch" ]; then