[Bash-completion-devel] RFC: complete only long options where they exist and work

Ville Skyttä ville.skytta at iki.fi
Tue Sep 29 17:28:28 UTC 2009


Hello,

I'd like to suggest that when we complete available options, we'd generally 
offer only the long options as completions if an option has a short 
option/alias/other counterpart and if it is known that the long option works 
well enough (basically if the long option takes no arguments, or takes an 
argument that can be separated with space (not only "=", but possibly both), 
it is ok).  For example, if let's say -f, -F, and --foo are equivalent, we 
offer only --foo out of them when $cur = -*.

My rationale is that it results in fewer suggestions and thus more streamlined 
operation (sometimes no suggestions but direct completion), and that whenever 
it results in more than one completion, the user is more likely to be able to 
choose what she wants from the set of possible long descriptive options than 
short ones or a mixture of them.

Note that we should still do option argument and other processing based on all 
the options given to the extent we can, even if they are the short ones, just 
like we do now - we'd just not generally list anything but long options that 
meet the above criteria and obviously short ones for which no corresponding 
long one exists.

For example, let's say if command foo takes -s, -S and --something all of 
which do the same thing, we list only --something when listing possible -* 
completions, but if that option takes an argument, we complete the possible 
arguments for all variants.

Simplified semi-pseudocode example: instead of doing:

    foo ()
    {
        case $prev in
            -s|-S|--something)
                do_something
                return 0
                ;;
        esac
        if [ $cur = "-*" ] ; then
            COMPREPLY=( $( compgen -W '-s -S --something' -- "$cur" ) )
        fi
    }

...we'd do:

    foo ()
    {
        case $prev in
            -s|-S|--something)
                do_something
                return 0
                ;;
        esac
        if [ $cur = "-*" ] ; then
            COMPREPLY=( $( compgen -W '--something' -- "$cur" ) )
        fi
    }

(so the only difference is the COMPREPLY=... line).

Thoughts?



More information about the Bash-completion-devel mailing list