From 58201b2ab70e90430c315868dd7317c56b1b7269 Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 25 Oct 2023 11:43:44 +0200 Subject: [PATCH] zsh: cleanup git functions --- functions/git.zsh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/functions/git.zsh b/functions/git.zsh index be7e444..16832d5 100644 --- a/functions/git.zsh +++ b/functions/git.zsh @@ -34,7 +34,6 @@ function git-sort-branch-by-usage(){ function git-switch-recent-branch(){ git switch $1 } -# compdef git-sort-branch-by-usage git-switch-recent-branch compdef "__git_completion_wrapper __git_recent_branches" git-switch-recent-branch function git-commit-show() { @@ -81,18 +80,26 @@ function gco() { if [[ "$#" -ge 1 ]]; then g checkout $@ elif [[ "$#" -eq 0 ]]; then - g checkout $(gb | fzf) + local selected + selected=$(git branch --format "%(refname)" | cut -d / -f 3- | fzf) + if [[ -n $selected ]]; then + git checkout "$selected" + else + echo "Nothing selected" + fi + fi } +compdef "__git_completion_wrapper _git-checkout" gco _disable_alias gcor function gcor() { if [[ "$#" -ge 1 ]]; then - g checkout $@ + git checkout $@ elif [[ "$#" -eq 0 ]]; then - g checkout --track $(gbr | fzf) + git checkout --track $(gbr | fzf) fi } @@ -110,9 +117,9 @@ compdef "__git_completion_wrapper __git_recent_branches" gbd _disable_alias gbD function gbD() { if [[ "$#" -ge 1 ]]; then - g branch -D $@ + git branch -D $@ elif [[ "$#" -eq 0 ]]; then - g branch -D $(gb | fzf -m) + git branch -D $(git branch | fzf -m) fi } compdef "__git_completion_wrapper __git_recent_branches" gbD