Skip to content

Commit 6f4cf0c

Browse files
authored
feat: delete-branch multiple unique branch names completions (#1221)
1 parent f5c48e4 commit 6f4cf0c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

etc/bash_completion.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# shellcheck shell=bash
22
# bash completion support for git-extras.
33

4+
__gitex_heads_unique() {
5+
local branch specified=("${COMP_WORDS[@]:2}")
6+
for branch in $(__git_heads); do
7+
[[ " ${specified[*]} " == *" $branch "* ]] || printf '%s\n' "$branch"
8+
done
9+
}
10+
411
_git_authors(){
512
__gitcomp "-l --list --no-email"
613
}
@@ -84,7 +91,7 @@ __git_cp(){
8491
}
8592

8693
_git_delete_branch(){
87-
__gitcomp "$(__git_heads)"
94+
__gitcomp "$(__gitex_heads_unique)"
8895
}
8996

9097
_git_delete_squashed_branches(){

etc/git-extras-completion.zsh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ __gitex_branch_names() {
7272
_wanted branch-names expl branch-name compadd $* - $branch_names
7373
}
7474

75+
__gitex_branch_names_unique() {
76+
local expl
77+
declare -a branch_names already_specified
78+
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
79+
__gitex_command_successful || return
80+
already_specified=(${words[2,-1]})
81+
_wanted branch-names expl branch-name compadd -F already_specified $* - $branch_names
82+
}
83+
7584
__gitex_specific_branch_names() {
7685
local expl
7786
declare -a branch_names
@@ -196,8 +205,7 @@ _git-create-branch() {
196205
}
197206

198207
_git-delete-branch() {
199-
_arguments \
200-
':branch-name:__gitex_branch_names'
208+
__gitex_branch_names_unique
201209
}
202210

203211
_git-delete-squashed-branches() {

0 commit comments

Comments
 (0)