deploy: support multi-branches (git deploy <remote> <branche...>) + complétion
This commit is contained in:
+26
-12
@@ -1,12 +1,14 @@
|
||||
# Complétion bash pour « git deploy » et « git hotfix ».
|
||||
# Complète le 1er argument avec les remotes, le 2e avec les branches locales,
|
||||
# le tout lu en direct depuis le dépôt courant.
|
||||
# git deploy : 1er arg = remote, args suivants = branches (multi-branches).
|
||||
# git hotfix : 1er arg = remote, 2e arg = branche.
|
||||
# Tout est lu en direct depuis le dépôt courant.
|
||||
#
|
||||
# À sourcer dans ~/.bashrc APRÈS la complétion git, par ex. :
|
||||
# source /chemin/vers/src/bin/deploy-completion.bash
|
||||
# source /chemin/vers/gitploy/deploy-completion.bash
|
||||
|
||||
_deploy_complete_positional() {
|
||||
local i args=() cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
# $1 = "multi" pour autoriser plusieurs branches, sinon une seule.
|
||||
_deploy_complete() {
|
||||
local multi="$1" i args=() cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
# Recense les arguments positionnels déjà saisis (hors options et valeur de -m)
|
||||
for ((i = 2; i < COMP_CWORD; i++)); do
|
||||
case "${COMP_WORDS[i-1]}" in -m|--message) continue ;; esac
|
||||
@@ -14,13 +16,25 @@ _deploy_complete_positional() {
|
||||
args+=("${COMP_WORDS[i]}")
|
||||
done
|
||||
|
||||
case "${#args[@]}" in
|
||||
0) COMPREPLY=($(compgen -W "$(git remote 2>/dev/null)" -- "$cur")) ;;
|
||||
1) COMPREPLY=($(compgen -W "$(git for-each-ref --format='%(refname:short)' refs/heads/ 2>/dev/null)" -- "$cur")) ;;
|
||||
*) COMPREPLY=() ;;
|
||||
esac
|
||||
local n=${#args[@]}
|
||||
if [ "$n" -eq 0 ]; then
|
||||
COMPREPLY=($(compgen -W "$(git remote 2>/dev/null)" -- "$cur"))
|
||||
return
|
||||
fi
|
||||
if [ "$multi" != multi ] && [ "$n" -ge 2 ]; then
|
||||
COMPREPLY=(); return
|
||||
fi
|
||||
|
||||
# Branches locales, en excluant celles déjà saisies.
|
||||
local all excl=" ${args[*]:1} "
|
||||
all=$(git for-each-ref --format='%(refname:short)' refs/heads/ 2>/dev/null)
|
||||
local avail=""
|
||||
for b in $all; do
|
||||
case "$excl" in *" $b "*) ;; *) avail="$avail $b" ;; esac
|
||||
done
|
||||
COMPREPLY=($(compgen -W "$avail" -- "$cur"))
|
||||
}
|
||||
|
||||
# Hooks reconnus par la complétion git pour les sous-commandes personnalisées.
|
||||
_git_deploy() { _deploy_complete_positional; }
|
||||
_git_hotfix() { _deploy_complete_positional; }
|
||||
_git_deploy() { _deploy_complete multi; }
|
||||
_git_hotfix() { _deploy_complete single; }
|
||||
|
||||
Reference in New Issue
Block a user