gvfs-mount -u und bash completion

Per gvfs eingehängte Devices oder Server-Verbindungen bequem per CLI aushängen. Da gvfs auf file://, sftp://, etc. basiert, darf der Doppelpunkt nicht als Worttrenner werdendet werden:

_gumount() {

        COMPREPLY=()
        local opts cur
        _get_comp_words_by_ref -n : cur
        opts=$(gvfs-mount -l -i | grep default_location | sed 's#.*default_location=\([^:]\+\):\(.*\)#\1\\:\2#')
        if [[ ! $opts ]] ; then
                return 1
        fi

        COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
        __ltrim_colon_completions "$cur"
        return 0
}
complete -F _gumount gumount

gmount() {
        if (($# != 1)) ; then
                cat <<EOF
Give me one device or network resource.
gmount /dev/sdc1
gmount sftp://leierkasten.local/root
EOF
                return 1
        fi
        opts=()
        if [[ -b $1 ]] ; then
                opts+=("-d")
        fi

        gvfs-mount "${opts[@]}" "$1"
}

Siehe auch: http://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-effecting-other-completion-script/12495480