views:

162

answers:

1

I have a list of unison profiles which exists in ~/.unison/*.prf.

I'd like to have bash completion so that when I type unison or unison-gtk and hit tab it would list the .prf files from that folder without the .prf part.

Perhaps an example would be clearer:

$ ls ~/.unison/*.prf
default.prf dot-mozilla.prf to-desktop.prf

$ cd  ~  # just to show you don't have to be in the ~/.unison folder
$ unison to<tab>
$ unison to-desktop

I foresee needing this for another tool as well, so it would be convenient if there were parts that could be reused.

+3  A: 

If you are running debian/ubuntu or possibly other GNU/Linux distros, there should be examples of this type of completion in your /etc/bash_completion.d/ directory. Here is an example of how you might set up a completion script for unison:

have unison &&
_unison_show()
{
        local cur

        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        COMPREPLY=($( compgen -W "$(for x in ~/.unison/*.prf; do echo $(basename ${x%.prf}); done)" -- $cur ) )
}
complete -F _unison_show unison
vezult
Works great, the only changes I did was complete -o nospace -F _unison_show unison unison-gtk
Scott Kirkwood