3

I have a list of words that should be present in the order of appearance in completion to a certain key, but bash seems to be internally sorting what is assigned to COMPREPLY array. How to avoid that?

Example:

_comm() {
    _init_completion -s -n : || return
    case $prev in
        -a) COMPREPLY=(zxy abcdef tyuu fgsfds)
            ;;
    esac
}
complete -F _comm comm

If you run this code, bash should complete

$ comm -a 

with

abcdef fgsfds tyuu zxy

i.e. sorted alphabetically.

4

Since Bash 4.4 you can use nosort option. In your example change last line to

complete -o nosort -F _comm comm

and you should get completions without alphabetical sorting.

Important note: options (specified with -o) must precede functions (-F). That’s why coderofsalvation’s code didn’t work.

0

This should be achieved by modifying the complete command:

complete -F _comm comm

into:

complete -F _comm comm -o nosort 

As mentioned in the documentation:

however I didn't get this to work on bash 4 :/

It seems it is a documented, yet not implemented feature of controlling readline's variable rl_sort_completion_matches.

More info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.