bash completion for unison

here's the first attempt to enable bash completion for unison; currently it only completes the profile names found in ~/.unison/. completion for command line arguments may follow ...

# cat /etc/bash_completion.d/unison

# unison bash completion
# Copyright 2007-2008 gregor herrmann <gregor+debian@comodo.priv.at>
# License: GNU GPL v2

have unison &&
_unison()
{
        local cur profiles
    
        [ -r $HOME/.unison ] || return 0

        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        profiles=$(cd $HOME/.unison/; ls *.prf | sed -e 's/\.prf//'g)

        if [ $COMP_CWORD -eq 1 ]; then
                COMPREPLY=( $(compgen -o filenames -W "$profiles" $cur) )
        fi

        return 0
}
[ "$have" ] && complete -F _unison unison

gregoa, 2007-02-23, 2007-04-27, 2008-05-17

Creative Commons License
All material on this blog — unless stated otherwise — is © gregor herrmann, and is licensed under the Creative Commons Attribution-Share Alike 3.0 Austria License.