From cf6d40d446e73c1047a26b907e2f82f9e545c6fd Mon Sep 17 00:00:00 2001 From: Daniele Paolella <53744340+danpaolella@users.noreply.github.com> Date: Fri, 29 Aug 2025 12:29:31 +0200 Subject: [PATCH] Improvements to Bash completion (#1210) * Sort Bash completion functions * feat: add Bash completion for `git rename-branch` * feat: add Bash completion for `git rename-remote` * feat: add Bash completion for `git rename-tag` * fix: use default completion for `git rename-file` * Refactor rename completion functions common logic --- etc/bash_completion.sh | 70 +++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 7a6360a..3139c57 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -1,6 +1,22 @@ # shellcheck shell=bash # bash completion support for git-extras. +_git_authors(){ + __gitcomp "-l --list --no-email" +} + +_git_browse(){ + __git_complete_remote_or_refspec +} + +_git_browse_ci(){ + __git_complete_remote_or_refspec +} + +_git_brv(){ + __gitcomp "-r --reverse" +} + _git_changelog(){ local s_opts=( '-a' '-l' '-t' '-f' '-s' '-n' '-p' '-x' '-h' '?' ) local l_opts=( @@ -22,14 +38,6 @@ _git_changelog(){ __gitcomp "$merged_opts_str" } -_git_authors(){ - __gitcomp "-l --list --no-email" -} - -_git_brv(){ - __gitcomp "-r --reverse" -} - _git_coauthor(){ local oldIfs=$IFS IFS=$'\n' @@ -136,6 +144,10 @@ _git_ignore(){ esac } +_git_info(){ + __gitcomp "--color -c --no-config" +} + _git_missing(){ # Suggest all known refs __gitcomp "$(git for-each-ref --format='%(refname:short)')" @@ -158,38 +170,40 @@ _git_reauthor(){ __gitcomp "${comp}" } -_git_scp(){ - __git_complete_remote_or_refspec +__git_extras_rename(){ + if ((COMP_CWORD == 2 || COMP_CWORD == 3)); then + __gitcomp "$1" + fi } -_git_stamp(){ - __gitcomp '--replace -r' +_git_rename_branch(){ + __git_extras_rename "$(__git_heads)" +} + +_git_rename_remote(){ + __git_extras_rename "$(__git_remotes)" +} + +_git_rename_tag(){ + __git_extras_rename "$(__git_tags)" } _git_rscp(){ __git_complete_remote_or_refspec } +_git_scp(){ + __git_complete_remote_or_refspec +} + _git_squash(){ __gitcomp "$(__git_heads)" } +_git_stamp(){ + __gitcomp '--replace -r' +} + _git_undo(){ __gitcomp "--hard --soft -h -s" } - -_git_info(){ - __gitcomp "--color -c --no-config" -} - -_git_browse(){ - __git_complete_remote_or_refspec -} - -_git_browse_ci(){ - __git_complete_remote_or_refspec -} - -_git_rename_file() { - __gitcomp "-h --help" -}