Skip to content

Commit

Permalink
Add Bash completion for show-release-notes command
Browse files Browse the repository at this point in the history
The completion will provide correct suggestions for all 3 arguments.
  • Loading branch information
extsoft committed Oct 8, 2019
1 parent b30e2a9 commit 8ab3896
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions completions/git-elegant.bash
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
#!/usr/bin/env bash

_git_elegant() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local cursor="${COMP_WORDS[COMP_CWORD]}"

case "${prev}" in
# the first word prior to the ${cursor}
case ""${COMP_WORDS[COMP_CWORD-1]}"" in
elegant|git-elegant)
opts=($(git elegant commands))
COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cur}) )
local opts=($(git elegant commands))
COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) )
return 0 ;;
pull|epull)
local data=$(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}')
COMPREPLY=( $(compgen -W "${data}" ${cur}) )
COMPREPLY=( $(compgen -W "${data}" ${cursor}) )
return 0 ;;
accept-work|obtain-work)
COMPREPLY=(
$(compgen -W "$(git branch --remotes --list)" -- ${cur})
$(compgen -W "$(git branch --remotes --list)" -- ${cursor})
)
return 0 ;;
*)
show-release-notes)
COMPREPLY=( $(compgen -W "simple smart" ${cursor}) )
return 0 ;;
*) ;;
esac

# the second word prior to the ${cursor}
case "${COMP_WORDS[COMP_CWORD-2]}" in
show-release-notes)
local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**))
COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) )
return 0 ;;
*) ;;
esac

# the third word prior to the ${cursor}
case "${COMP_WORDS[COMP_CWORD-3]}" in
show-release-notes)
local opts=($(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/**))
COMPREPLY=( $(compgen -W "${opts[*]}" -- ${cursor}) )
return 0 ;;
*) ;;
esac
}

Expand Down

0 comments on commit 8ab3896

Please sign in to comment.