From: Jani Nikula <jani.nikula@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: Re: [maintainer-tools PATCH 1/8] completion: require bash completion package and use it
Date: Fri, 19 Feb 2016 16:31:56 +0200 [thread overview]
Message-ID: <878u2gwz37.fsf@intel.com> (raw)
In-Reply-To: <1455812454-19187-1-git-send-email-jani.nikula@intel.com>
On Thu, 18 Feb 2016, Jani Nikula <jani.nikula@intel.com> wrote:
> The bash completion package makes life a whole lot easier than using the
> builtin bash completion features. It's quite likely anyone using
> completion in bash already has it installed.
I boldly went ahead and pushed the lot. Please scream if
https://xkcd.com/1172/.
BR,
Jani.
>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
> bash_completion | 62 ++++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 35 insertions(+), 27 deletions(-)
>
> diff --git a/bash_completion b/bash_completion
> index e44e5fc844b4..6a3a88cc80f8 100644
> --- a/bash_completion
> +++ b/bash_completion
> @@ -11,7 +11,21 @@ dim ()
>
> _dim ()
> {
> - local cur cmds opts i
> + local args arg cur prev words cword split
> + local cmds
> +
> + # require bash-completion with _init_completion
> + type -t _init_completion >/dev/null 2>&1 || return
> +
> + _init_completion || return
> +
> + COMPREPLY=()
> +
> + # arg = subcommand
> + _get_first_arg
> +
> + # args = number of arguments
> + _count_args
>
> if [ -f ~/linux/drm-intel-rerere/nightly.conf ] ; then
> local nightly_branches=`(source ~/linux/drm-intel-rerere/nightly.conf ; echo $nightly_branches) | \
> @@ -35,27 +49,21 @@ _dim ()
> cmds="$cmds create-branch remove-branch create-workdir for-each-workdirs fw"
> cmds="$cmds tag-next checker"
>
> - opts="-d -f -i"
> -
> - i=1
> -
> - COMPREPLY=() # Array variable storing the possible completions.
> - cur=${COMP_WORDS[COMP_CWORD]}
> -
> - for comp in "${COMP_WORDS[@]}" ; do
> - for opt in $opts ; do
> - if [[ $opt = $comp ]] ; then
> - i=$((i+1))
> - fi
> - done
> - done
> -
> - if [[ $COMP_CWORD == "$i" ]] ; then
> - COMPREPLY=( $( compgen -W "$cmds $opts" -- $cur ) )
> + if [ -z "${arg}" ]; then
> + # top level completion
> + case "${cur}" in
> + -*)
> + local opts="-d -f -i"
> + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
> + ;;
> + *)
> + COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
> + ;;
> + esac
> return 0
> fi
>
> - case "${COMP_WORDS[i]}" in
> + case "${arg}" in
> push-branch)
> COMPREPLY=( $( compgen -W "-f $nightly_branches" -- $cur ) )
> ;;
> @@ -69,7 +77,7 @@ _dim ()
> COMPREPLY=( $( compgen -W "-s" -- $cur ) )
> ;;
> magic-patch|mp)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -o nospace -W "-a" -- $cur ) )
> fi
> ;;
> @@ -80,34 +88,34 @@ _dim ()
> # FIXME needs a git sha1
> ;;
> pull-request)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
> - elif [[ $COMP_CWORD == "$((i+2))" ]] ; then
> + elif [[ $args == 3 ]]; then
> COMPREPLY=( $( compgen -W "$upstream_branches" -- $cur ) )
> fi
> ;;
> pull-request-next|pull-request-fixes|pull-request-next-fixes)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -W "$upstream_branches" -- $cur ) )
> fi
> ;;
> create-branch)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -o nospace -W "drm- topic/" -- $cur ) )
> fi
> ;;
> checkout|co)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
> fi
> ;;
> remove-branch)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
> fi
> ;;
> create-workdir)
> - if [[ $COMP_CWORD == "$((i+1))" ]] ; then
> + if [[ $args == 2 ]]; then
> COMPREPLY=( $( compgen -W "$nightly_branches all" -- $cur ) )
> fi
> ;;
--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
prev parent reply other threads:[~2016-02-19 14:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-18 16:20 [maintainer-tools PATCH 1/8] completion: require bash completion package and use it Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 2/8] dim: add list-branches subcommand to list nightly branches Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 3/8] dim: add list-upstreams subcommand to list upstream branches Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 4/8] completion: use the dim helpers to complete nightly and " Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 5/8] dim: add list-commands subcommand to list all subcommands Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 6/8] dim: rename alias subcommand to list-aliases Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 7/8] completion: use the dim helpers to complete subcommands and aliases Jani Nikula
2016-02-18 16:20 ` [maintainer-tools PATCH 8/8] completion: complete aliases like the actual command Jani Nikula
2016-02-19 14:31 ` Jani Nikula [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878u2gwz37.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.