Score:0

Is there a way to make the bash auto-complete show a different completion list than what will be used to actually auto-complete?

bd flag

first question here ^^

I have a an auto-completion script which contains this :

    COMPREPLY=()
    mapfile -t MAP< <(compgen -A directory -- "$cur")
    for entry in "${MAP[@]}"; do
#       if [[ "$entry" =~ ([^/]*$) ]]; then
#           COMPREPLY+=("$(printf "%q" "${BASH_REMATCH[1]}")")
            COMPREPLY+=("$(printf "%q/" "$entry")")
#       fi
    done;;

The goal is to autocomplete a command with a directory name so that mycmd m[TAB] will be completed as mycmd mydir/

This works just fine, but if I have 2 directories mydir1 mydir2 and I am in mydir1, then mycmd ../m[TAB] will display ../mydir1 ../mydir2.

I want to be able to autocomplete to mycmd ../mydir1 while only displaying mydir1 mydir2 just as ls ../ does. The commented lines allow me to change the display as wanted but autocompletes as mycmd mydir1 which is incorrect.

Is it possible to display mydir1 mydir2 while autocompleting as mycmd ../mydir1 ?

Thanks !

muru avatar
us flag
That's the behaviour you get by `complete -d mycmd`, so if your completion is complex and changes based on the word being completed, check out the section starting "There is some support for dynamically modifying completions" in https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion
Bastougne avatar
bd flag
It is roughly the behaviour of `complete -d mycmd` because it is able to correctly autocomplete directories with spaces, but it doesn't change much here. According to the doc, `complete -o plusdirs -D mycmd` seems to do the trick
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.