diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 3139c575..fa561efe 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -1,6 +1,13 @@ # shellcheck shell=bash # bash completion support for git-extras. +__gitex_heads_unique() { + local branch specified=("${COMP_WORDS[@]:2}") + for branch in $(__git_heads); do + [[ " ${specified[*]} " == *" $branch "* ]] || printf '%s\n' "$branch" + done +} + _git_authors(){ __gitcomp "-l --list --no-email" } @@ -84,7 +91,7 @@ __git_cp(){ } _git_delete_branch(){ - __gitcomp "$(__git_heads)" + __gitcomp "$(__gitex_heads_unique)" } _git_delete_squashed_branches(){ diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 13957f06..0ab03d26 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -72,6 +72,15 @@ __gitex_branch_names() { _wanted branch-names expl branch-name compadd $* - $branch_names } +__gitex_branch_names_unique() { + local expl + declare -a branch_names already_specified + branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}) + __gitex_command_successful || return + already_specified=(${words[2,-1]}) + _wanted branch-names expl branch-name compadd -F already_specified $* - $branch_names +} + __gitex_specific_branch_names() { local expl declare -a branch_names @@ -196,8 +205,7 @@ _git-create-branch() { } _git-delete-branch() { - _arguments \ - ':branch-name:__gitex_branch_names' + __gitex_branch_names_unique } _git-delete-squashed-branches() {