From 451e51bd88161473d82aeb1b473dd05312dbfabe Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 5 Feb 2018 10:44:59 -0500 Subject: [PATCH] [git] Add git-branch-delete-interactive that prompts if upstream remote branch(es) should be deleted too. As with `git branch`, the function supports multiple branches as params, and also the `-r`/`--remotes` param. Update `gbx` and `gbX` to use this function. Also update `git-stash-clear-interactive` to have multiple tests instead of multiple nested `if`/`then`/`fi`. (Simpler syntax, IMHO) --- .../git/functions/git-branch-delete-interactive | 16 ++++++++++++++++ .../git/functions/git-stash-clear-interactive | 8 ++++---- modules/git/init.zsh | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 modules/git/functions/git-branch-delete-interactive diff --git a/modules/git/functions/git-branch-delete-interactive b/modules/git/functions/git-branch-delete-interactive new file mode 100644 index 0000000..9a7f6a3 --- /dev/null +++ b/modules/git/functions/git-branch-delete-interactive @@ -0,0 +1,16 @@ +# vim:et sts=2 sw=2 ft=zsh +local -a remotes +if (( ${*[(I)-r]} || ${*[(I)--remotes]} )); then + remotes=(${^*:#-*}) +else + remotes=(${(f)"$(command git rev-parse --abbrev-ref ${^*:#-*}@{u} 2>/dev/null)"}) +fi +if command git branch --delete ${@} && \ + (( ${#remotes[@]} )) && \ + read -q "?Also delete remote branch(es) ${remotes} [y/N]? "; then + print + local remote + for remote (${remotes}); do + command git push ${remote%%/*} :${remote#*/} + done +fi diff --git a/modules/git/functions/git-stash-clear-interactive b/modules/git/functions/git-stash-clear-interactive index eb93178..b677b2a 100644 --- a/modules/git/functions/git-stash-clear-interactive +++ b/modules/git/functions/git-stash-clear-interactive @@ -3,8 +3,8 @@ setopt LOCAL_OPTIONS PIPE_FAIL local -i stashed stashed=$(command git stash list | wc -l) || return 1 -if (( stashed )); then - if read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then - command git stash clear - fi +if (( stashed )) && \ + read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then + print + command git stash clear fi diff --git a/modules/git/init.zsh b/modules/git/init.zsh index 54916fd..d53082d 100644 --- a/modules/git/init.zsh +++ b/modules/git/init.zsh @@ -29,8 +29,8 @@ alias gbm='git branch --move' alias gbM='git branch --move --force' alias gbs='git show-branch' alias gbS='git show-branch --all' -alias gbx='git branch --delete' -alias gbX='git branch --delete --force' +alias gbx='git-branch-delete-interactive' +alias gbX='git-branch-delete-interactive --force' # Commit (c) alias gc='git commit --verbose'